-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[core] Synchronise value and checked prop typing #15245
Conversation
249d81b
to
c0397c4
Compare
No bundle size changes comparing 8a67ecc...96a937c |
23ceb2b
to
01ec465
Compare
01ec465
to
c1b077b
Compare
I've left the progress indicators and Slider value props as numbers |
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.
Sorry that I didn't mention that at first but we should use unknown
for the types. I'm taking care of this as well as looking to event.target.value
for select related components
Should we do the propTypes & TypeScript changes in two different pull requests? |
They're both concerned with types. Since TypeScript is coupled with prop-types we should have them in one commit. |
I agree in general. I was wondering as each commit would create value. I'm happy to move both as a whole. |
PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool, PropTypes.object]), | ||
), | ||
]), | ||
value: PropTypes.any, |
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.
At some point we should remove those. We usually don't document props from the root component. I guess keeping them here is more pragmatic. Once our docs are able to expand all props without having to keep multiple tabs open we can remove these here.
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.
Correct, we break the rule to make the input component easier to use.
If we need any value support we should implement this in another PR. Right now anything but strings is dangerous because of JS weak typing. |
@@ -110,7 +110,7 @@ RadioGroup.propTypes = { | |||
/** | |||
* Value of the selected radio button. | |||
*/ | |||
value: PropTypes.any, | |||
value: PropTypes.string, |
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.
What's wrong with any here?
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.
See 757384e
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.
Correct. We would need to cast the values to a string in the comparison to support any
:
let checked = checkedProp;
const onChange = createChainedFunction(onChangeProp, radioGroup && radioGroup.onChange);
let name = nameProp;
if (radioGroup) {
if (typeof checked === 'undefined') {
- checked = radioGroup.value === props.value;
+ checked = String(radioGroup.value) === String(props.value);
I believe it's the only change required.
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.
Have you looked at the test?
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 have. My proposed change would only support string | number | boolean
. But as you said, it's a topic for another pull request. Is this important? I'm not sure.
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.
Pretty sure boolean would break easily and number is still dangerous.
This allows for easier integration with redux-form without warning in the console.
instead of
Edit @eps1lon:
Closes #14286, #13782