-
-
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
[TextField] value propType #6091
Conversation
Allow input to accept a string or a number
@@ -130,7 +130,7 @@ export default class Input extends Component { | |||
/** | |||
* The input value, required for a controlled component. | |||
*/ | |||
value: PropTypes.string, | |||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
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 about 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.
I am fine with any
since it lets me pass in a number without errors....but does it make sense to allow arrays and objects and functions for an input? Or is it better that we just check something is sent in, and if your passing non scalar values that's on you? I'd be glad to change this to any just let me know your thoughts on allowing non scalar values
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.
but does it make sense to allow arrays and objects and functions for an input?
Good point, I'm pretty convinced people we ask for it. I could ask the same question, does it makes sense to provide a number and not a string? People will try to provide boolean too.
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.
Shouldn't that be:
import propTypes from '../utils/propTypes';
[...]
value: propTypes.stringOrNumber,
?
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.
Oh, I didn't know we had stringOrNumber
. I would rather remove that helper.
I don't think that this abstraction add much value.
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.
It's only used in one other place, so easily done. I guess it will go away with next
...
Allow Input component to except a number or a string as its value prop...instead of just string