I have a material-ui select box that is populated with a state variable. No matter what I have tried, I cannot get the value to actually show when I select an option. Can anyone tell me why? It keeps just giving me a blank bar. I even took an example from another code sandbox and copied it almost exactly. One thing I did notice is that my event.target.value is always undefined, and I am not sure why. So I just use value, instead, in my handleChange function. Any help is greatly appreciated! This has been driving me crazy.
Code Sandbox: https://codesandbox.io/s/jnyq16279v
Code:
import React from 'react'; import MenuItem from 'material-ui/MenuItem'; import Select from 'material-ui/SelectField'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; export default class KKSelect extends React.Component { constructor(props) { super(props); this.state = { selectOptions: [ { value: "Image", id: "1" }, { value: "Integer", id: "2" }, { value: "Decimal", id: "3" }, { value: "Boolean", id: "4" }, { value: "Text", id: "5" } ], selectedValue: "" }; } renderSelectOptions = () => { return this.state.selectOptions.map((dt, i) => { return ( <MenuItem key={i} value={dt.id}> {dt.value} </MenuItem> ); }); } handleChange = (event, value) => { this.setState({ selectedValue: value }); }; render() { return ( <MuiThemeProvider> <Select value={this.state.selectedValue} onChange={this.handleChange} > {this.renderSelectOptions()} </Select> </MuiThemeProvider> ); } }