Code Monkey home page Code Monkey logo

Comments (4)

AlexLisenkov avatar AlexLisenkov commented on June 16, 2024

Hi @seyade ,

The defaultChecked is not a property of Checkbox but instead of CheckboxGroup.
Applying defaultChecked to the checkboxGroup will check all checkboxes by default.

If you wish to check a single Checkbox you can simply pass checked to it.

from grouped-checkboxes.

seyade avatar seyade commented on June 16, 2024

Thanks @AlexLisenkov for replying. And great work by the way!

I think defaultChecked should also be applied to Checkbox as it is a supported props in React. For example I have a table full of checkboxes (about 50) in all columns and rows. I can populate the checkboxes with data from an api, but I also want to give users the choice to uncheck/check a populated checkbox. Using defaultChecked makes life easier in this context, I think.

from grouped-checkboxes.

AlexLisenkov avatar AlexLisenkov commented on June 16, 2024

Thank you for pointing out this issue, I believe there is something wrong with a Checkbox being controlled or not.

The misunderstanding, or flaw, is that the checked prop is now behaving like a defaultChecked. I agree with you, and the defaultChecked should be allowed and set the initial checked state.

If we add the defaultChecked there we will be left with the choice about what we should do with the checked prop.

  1. Disallow (or ignore) the checked prop, making it impossible to control checked states. Checkboxes will always and only be controlled by the group.

  2. Allow the checked prop, making it behave exactly like a checkbox. But making a checkbox controlled it will be impossible to make use of the allCheckers and noneCheckers, because they're not in charge of the state of a checkbox anymore.

Going for option 2 will be nice in a way that it will behave like a checkbox as how we're used to it. But it will also void the main feature of this package, easily add a checkbox to check all.

Can you give your opinion?

from grouped-checkboxes.

seyade avatar seyade commented on June 16, 2024

I guess, the most viable option will be to leave as it is since checked prop is the main prop for controlling state. Unless you give the user option to choose between defaultChecked and checked when necessary, but that will be too much for something simple like this.

from grouped-checkboxes.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.