-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
Fix “no onChange handler” warning to fire on falsy values ("", 0, false) too #12628
Fix “no onChange handler” warning to fire on falsy values ("", 0, false) too #12628
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon yeah that makes total sense, I’ll add something to check for that tonight. |
@gaearon I’ve added those checks, thanks for your patience 😄 |
@@ -936,14 +1000,18 @@ describe('ReactDOMInput', () => { | |||
|
|||
it('should warn if value is null', () => { | |||
expect(() => | |||
ReactTestUtils.renderIntoDocument(<input type="text" value={null} />), | |||
ReactTestUtils.renderIntoDocument( | |||
<input type="text" value={null} onChange={emptyFunction} />, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these changes are now unnecessary and can be reverted? We still expect one warning with null
even if you don't pass onChange
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes gotcha 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good now!
it('should warn of no event listener with a falsey checked prop', () => { | ||
expect(() => | ||
ReactTestUtils.renderIntoDocument( | ||
<input type="checkbox" checked="false" />, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong. "false"
is not falsy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the behavior is right but the test title is confusing.
118ee8e
to
9cfbed6
Compare
I did some minor changes — reverted unnecessary test tweaks, and also fixed |
References issue #12477
Description
What is the current behavior?
(Bug / Inconsistency)
No Warning.
Warning: Failed prop type: You provided a 'checked' prop to a form field without an 'onChange' handler. This will render a read-only field. If the field should be mutable use 'defaultChecked'. Otherwise, set either 'onChange' or 'readOnly’.’
*Note: was also happening with truthy values that == false (ex “0”)
Steps