-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Warn when value and defaultValue props are both specified on input or textarea. #5823
Conversation
if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValDefaultVal) { | ||
warning( | ||
false, | ||
'Both `value` and `defaultValue` props on `input` should not be specified. ' + |
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.
The first sentence in this error message makes it sound like neither of the props should be specified. It says "both... props... should not be specified". Alternative wording:
Input elements must be either controlled or uncontrolled (specify either the
value
prop, or thedefaultValue
prop, but not both). Decide between using a controlled or uncontrolled input and remove one of these props. More info: https://fb.me/react-controlled-components
@mgmcdermott This looks really great! Can you update the wording of the error messages, as per above, and then I think this is good-to-go. |
See the new PR. Glad I could help @jimfb. Nice to get my feet wet contributing as well. |
Looks good. Can you squash these two commits into a single commit. You can do this using |
Oh, sorry, and one more thing I just noticed: |
I'll update to include checked/defaultChecked. |
@mgmcdermott updated the pull request. |
Would this also apply to a select element using the value and defaultValue props? |
Changed my comment, I meant a select element. From the source: Implements a select native component that allows optionally setting the props |
Yes, this should also apply to select element :). |
…d props are specified on input, textarea, or select elements
See the latest PR, I think I've covered everything. |
@mgmcdermott updated the pull request. |
This looks great, thanks @mgmcdermott! |
Warn when value and defaultValue props are both specified on input or textarea.
@mgmcdermott If you're looking for another bug related to controlled inputs, you might take a stab at #5821, which would be a great next bug. |
Will do! Thanks. |
Fixes #5819.
Note that I've been using React for a while but this is my first time contributing.