Support objects with <Select>
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Not showing warnings when passing an object as value to the Select component.
Current Behavior
It works but it is showing these warnings:
Warning: Failed prop type: Invalid prop 'value' supplied to 'Select'.
Warning: Failed prop type: Invalid prop 'value' supplied to 'Input'.
Warning: Failed prop type: Invalid prop 'value' supplied to 'SelectInput'.
Steps to Reproduce (for bugs)
Thats my component in which I use the Select component. As you can see this.props.selectedWorkingStep
is an object which causes those warnings.
class WorkingStepSelect extends React.Component {
render() {
return <FormControl error={this.props.error} className={this.props.classes.formControl}>
<InputLabel htmlFor="workingStepSelect">{germanMessages.resources.controls.workingStepSelect.label}</InputLabel>
<Select
value={this.props.selectedWorkingStep}
onChange={this.props.onChangeWorkingStep}
input={<Input name="workingStep" id="workingStepSelect" />}
>
{this.props.workingSteps.map((workingStep) => {
return <MenuItem key={workingStep.id} value={workingStep}>{workingStep.name}</MenuItem>
})}
</Select>
<FormHelperText className="error-message" error={this.props.error}>{germanMessages.resources.controls.workingStepSelect.errorMessages[this.props.error]}</FormHelperText>
</FormControl>
}
}
PropTypes:
WorkingStepSelect.propTypes = {
selectedWorkingStep: PropTypes.any,
workingSteps: PropTypes.arrayOf(PropTypes.object),
onChangeWorkingStep: PropTypes.func,
error: PropTypes.any,
classes: PropTypes.object
};
CodeSandbox example
https://codesandbox.io/s/8x8r5plx32?module=%2Fsrc%2Fpages%2Findex.js
Context
Its not that critical because it is working for me(maybe there are errors which I don’t encountered yet). Maybe #10834 has the same problem but I don’t know it is the same reason for the warning because my warnings show up not depending on if I select an item of the Select.
Your Environment
Tech | Version |
---|---|
Material-UI | material-ui@1.0.0-beta.34 |
React | react@16.2.0 |
browser | Chrome Version 65 |
etc |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:29
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Select-Object (Microsoft.PowerShell.Utility)
The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of...
Read more >Support objects with <Select> · Issue #10845 · mui/material-ui
Not showing warnings when passing an object as value to the Select component. Current Behavior. It works but it is showing these warnings:....
Read more >Selecting an object in the Object Explorer - SQL Prompt 10
Supported objects. SQL Prompt can select all objects and columns in the Object Explorer except: columns in linked tables ...
Read more >SelectObjectContent - Amazon Simple Storage Service
Amazon S3 Select does not support whole-object compression for Parquet objects. Server-side encryption - Amazon S3 Select supports querying objects that are ...
Read more >Cannot select multiple objects in AutoCAD
AutoCAD: When trying to add additional objects to a selection, the previously selected ... Support Overview; Learn; Troubleshooting; Forums.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that the best step going forward is to write a custom prop-type validator. The warning message isn’t actionable right now: https://github.com/mui-org/material-ui/blob/7f73f967c1f8c405eb14304de0bbd1aeae5b4d71/src/TextField/TextField.js#L261-L265
@npeham Thanks a lot for the reproduction example! The
value
proptype isn’tany
. It has to be a string or a number (or an array of this). You are providing an object to the component:While it’s “working”, it comes with two drawbacks:
native={true}
works great on mobile.value="[object Object]"
It’s important when you are using React and Material-UI as a server-side templating engine without client-side rendering and in different other niche use cases. I also “believe” it helps with accessibility.Here is an updated version without the warning https://codesandbox.io/s/1yvymk2r67.
Now, I think that we should something about this confusing warning message. I have seen it too personally, wtf:
Warning: Failed prop type: Invalid prop 'value' supplied to 'Select'.