Unable to Select options from select component using material ui react

Advi

I'm working on material ui react storybook . I have given customised select options but when i select options it is not selecting. Below is what i have tried if option 1 is selected it not taking any value. How do i select options ? I cannot use TextField , because i'm working on select component. I have to achieve this with the Mapping. Thanks. Below is My code.

    export const SelectBasic= ({
        props,
       selectoptions,
    }) => {
    
        const theme = useTheme();
        const [age, setAge] = React.useState('');
    
        const handleChange = (event: SelectChangeEvent) => {
            setAge(event.target.valueasstring);
        };
    
        return (
            <div>               
                    <FormControl fullWidth >
                        <InputLabel id="demo-simple-select-label">Age</InputLabel>
                        <Select
                            labelId="demo-simple-select-label"
                            id="demo-simple-select"
                            value={age}
                            label="Age"
                            onChange={handleChange}
    
                        >
                           {selectoptions.map(item => {
                        return (
                            <MenuItem value={item.label}>{item.label}</MenuItem>
                        )
                    })}
    
                        </Select>
                    </FormControl>               
            </div >
        );
    }

stories.js

export const Selectdef = SelectBasic.bind({});
Selectdef .args = {    
   selectoptions: [{ "label": "Option 1" }, { "label": "Option 2" }, { "label": "Option 3" }],

};

Yone

const {
  Box,
  FormControl,
  InputLabel,
  MenuItem,
  Select,
  Typography
} = MaterialUI;

const OPTIONS = [{
    value: 10,
    label: 'ten'
  },
  {
    value: 20,
    label: 'twenty'
  },
  {
    value: 30,
    label: 'thirty'
  }
];

const BasicSelect = ({options}) => {
  const [age, setAge] = React.useState('');

  const handleChange = (event) => {
    setAge(event.target.value);
  };

  return (
    <Box sx={{ minWidth: 120 }}>
      <FormControl fullWidth>
        <InputLabel id="demo-simple-select-label">Age</InputLabel>
        <Select
          labelId="demo-simple-select-label"
          id="demo-simple-select"
          value={age}
          label="Age"
          onChange={handleChange}
        >
{options.map(item => <MenuItem value={item.value}>{item.label}</MenuItem>)}
        </Select>
      </FormControl>
      <Typography>{`Currently selecting: ${age || 'undefined'}`}</Typography>
    </Box>
  );
}


ReactDOM.render( <BasicSelect options={OPTIONS} / > ,
  document.getElementById("root")
);
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@mui/material@latest/umd/material-ui.production.min.js"></script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make a 'Select' component as required in Material UI (React JS)

Material UI Select component crashing React application

How to update a multi select options from component

React testing library on change for Material UI Select component

Select Component's inputProps (Material UI)

React Hooks : UseRef not recognizing Event from Material UI Select

material ui warning in using `textField` component with `select`

Problem with using map to populate select in React / Material UI

Unable to test Angular Material Select Component using CDK Test Harness

Remove blue outline from Select box React Material UI

Set JSON object to a Const on material UI Select component React Hooks

Material UI select throws event.target.getAttribute is not a function when used from within react-datatable-component

react material-ui select You have provided an out-of-range value `undefined` for the select component

material ui select component dropdown positioning

How to style react material ui select component height

react-select component options are not applied

Preselect an element from the list of elements in Material-UI Select component

Material UI Select not showing options

Disable "Select By Typing" in Material UI Menu Component

setValue from material UI select

Bordercolor override in Select component material ui on error

unable to only select a single material ui checkbox

How to style material-ui select component with style-components (not material-ui classes!) in react?

React+Material UI: How to change the font size of the Select component?

Select All options using React Select

Dynamically create select options using material UI create

Change label of Select Component using material ui react

How to set a default value for a Select component from react with MenuItem as options

Material UI: You have provided an out-of-range value for the select component, despite value being in the options list