question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Reactions:29
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
oliviertassinaricommented, Mar 29, 2018

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

3reactions
oliviertassinaricommented, Mar 29, 2018

@npeham Thanks a lot for the reproduction example! The value proptype isn’t any. It has to be a string or a number (or an array of this). You are providing an object to the component:

  {
    id: 1,
    name: "StepOne"
  }

While it’s “working”, it comes with two drawbacks:

  • You can’t switch on and off the native property base on your environment. For instance, native={true} works great on mobile.
  • The value can’t be serialized and sent down to the server with a raw POST/GET request: value="[object Object]" capture d ecran 2018-03-29 a 22 41 40 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'.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found