Skip to content

[select] Support objects value #10845

Description

@npeham
  • 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 [email protected]
React [email protected]
browser Chrome Version 65
etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: selectChanges related to the select.type: new featureExpand the scope of the product to solve a new problem.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions