-
Notifications
You must be signed in to change notification settings - Fork 231
Provide controlled Checkbox #552
Comments
Is this a dup of #438? |
I don't understand the core issue behind #438. Is it about making the React code more semantically similar to the HTML output? Is there a record of the problem from the Discord chat somewhere? |
#438 provides access to the Regarding your original request. The checkbox component does have that functionality. From lines 84 to 95:
|
The problem with the current API is that the component is halfway between a controlled and uncontrolled component. If you set the value the checkbox updates, but if the user clicks the checkbox and you don't update the value then the checkbox's state falls out of sync with the value prop which can be problematic. Furthermore it's not possible to prevent the checkbox's value from changing by listening to React handles this elegantly by providing If instead you set I've created a small demo here: http://jsfiddle.net/ytq61r8a/1/. What I'd like to do is provide users with the same API as they get when using a vanilla React |
@levibotelho, after reading your last post it sounds like the proposed fix of #438 would also fix the issue you're encountering. The idea is to allow people to compose the checkbox like so:
With this change, you should be able to pass whatever props you'd like. |
@moog16 makes sense, thanks! |
It should be possible to use Checkbox as a controlled component. Currently it takes a
checked
prop, but clicking on the checkbox changes the value even ifchecked
isn't updated.I suggest changing
checked
todefaultChecked
, and adding a newchecked
property that when set makes the Checkbox act like a controlled component.I'm happy to do the work for this change.
The text was updated successfully, but these errors were encountered: