-
-
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
[Select] Support object value #13661
[Select] Support object value #13661
Conversation
1b01bc9
to
f6ea91b
Compare
f6ea91b
to
0e6d7f1
Compare
@@ -133,7 +133,15 @@ Input.propTypes = { | |||
/** | |||
* The default input value, useful when not controlling the component. | |||
*/ | |||
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | |||
defaultValue: PropTypes.oneOfType([ |
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 will voice my concerns once again because this is increasingly magic since the value will be cast to string. People should do that explicitly so that the component appears to be less magic. Allowing numbers is already bad as it is since numbers will go in but strings will come out.
Especially for something like objects it doesn't make much sense to allow them since most of them will generate the same value ([object Object]
).
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'm not a fan either, but many people ask for it. At this point, we might just use any for the propType, like React is doing for <input>
. Now, most people use an XHR to send the form values to the server. They don't care about the [object Object]
DOM casting. Also, as we don't cast objet to string in the non native select implementation, this works.
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.
Well if you access event.target.value
then you should care about casting. I was hoping we could add a more predictable wrapper around input
since type coercion is imo one of the bigger issues in JS since it can't be addressed with linters.
But since we already allowed this with numbers we might as well be consistent. PropTypes.any
it is.
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.
Having object select support definitely comes with a cost :/. Does it worth it?
I'm going to merge this pull-request. To sum up:
|
In
Select
component, the propertyvalue
supportobject
type. The value will pass intoInput
andInputBase
components. But it is not supported inInput
andInputBase
.What's more, I think that the property
defaultValue
should support the same types as propertyvalue
.Closes #10845