Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since 15.2.0 TestUtils for Radios and Checkboxes Unexpected Behavior for null checked attributes #7660

Closed
dtothefp opened this issue Sep 5, 2016 · 3 comments

Comments

@dtothefp
Copy link

dtothefp commented Sep 5, 2016

Do you want to request a feature or report a bug?
bug

What is the current behavior?
When using ReactDOM.render checkboxes with jsx attribute checked={null} will have a checked value from their DOM element of false. When using TestUtils and TestUtils.Simulate the same configuration above for checked={null} will result in checkboxElm.checked to be true.

**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

demo here https://jsbin.com/ciwavowoqe/1/edit?html,js,console,output

What is the expected behavior?
expected behavior is that TestUtils would mimic actual DOM fragment, i.e. jsx property checked={null} results in someCheckboxElm.checked to be false

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
This worked in 15.1.0 but stopped working in >= 15.2.0

@dtothefp dtothefp changed the title Since 15.2.0 TestUtils for Radios and Checkboxes Unexpected Behavior for null checked values Since 15.2.0 TestUtils for Radios and Checkboxes Unexpected Behavior for null checked attributes Sep 5, 2016
@nhunzaker
Copy link
Contributor

I pushed for this in #7530. The explanation I was given was that "null" activates uncontrolled mode for inputs, which is why you are seeing the behavior.

@dtothefp
Copy link
Author

dtothefp commented Sep 5, 2016

@nhunzaker thanks for the heads up. from reading that I'm still not clear on why I'm seeing null work for toggling checked unless I use the TestUtils...seems inconsistent?

@gaearon
Copy link
Collaborator

gaearon commented Oct 4, 2017

Switching checked to null switches your input to be uncontrolled.
React 16 warns about this:

screen shot 2017-10-04 at 14 09 10

I think what happens next is: when you click on it manually, the browser toggles it (now that it’s uncontrolled). So you see it changing. Whereas if you simulate an event with TestUtils, nothing happens because your click handler just switched it to uncontrolled mode but there was no real click.

As the warning suggests, don’t use null unless you mean for the component to be uncontrolled (in which case you should keep it uncontrolled for its whole lifetime).

Hope this helps!

@gaearon gaearon closed this as completed Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants