why is onClick not working in material-ui option?
<Select native labelId="select-demo" id="status-select" value={value} displayEmpty onChange={handleChangeSelect} > <option aria-label="None" value="" disabled/> <option value={1} onClick={modalOpen}>Confirmed</option> <option value={2}>Preparing</option> <option value={3}>On the Way</option> <option value={4}>On the Way (Delayed)</option> <option value={5}>Completed</option> </Select> And this is my modalOpen. I just wanted to try it with alert first before coding the modal.
const modalOpen = (event) => { alert('Are you sure?'); } And this is my updated code where onClick is already working but then I am also getting this error
SelectInput.js:342 Material-UI: You have provided an out-of-range value `false` for the select component. Consider providing a value that matches one of the available options or ''. The available values are `10`, `20`, `30`, `40`, `50`. const handleClickOpen = () => { setOpen(true); }; const handleClose = () => { setOpen(false); }; const handleChange = (event) => { const name = event.target.name; setState({ ...state, [name]: event.target.value, }); }; <FormControl> <Select labelId="select-demo" id="status-select" value={status} onChange={handleChange} > {/* <option aria-label="None" value="" disabled/> */} <MenuItem value ={10} onClick={handleClickOpen}>Confirmed</MenuItem> <MenuItem value ={20}>Preparing</MenuItem> <MenuItem value ={30}>On the Way</MenuItem> <MenuItem value ={40}>On the Way (Delayed)</MenuItem> <MenuItem value ={50}>Delivered</MenuItem> </Select> </FormControl> And this is my dialog/modal that I used from material-ui:
<Dialog open={open} onClose={handleClose} aria-labelledby="alert-dialog-title" aria-describedby="alert-dialog-description" > <DialogTitle id="alert-dialog-title">{"Order Status"}</DialogTitle> <DialogContent> <DialogContentText id="alert-dialog-description"> Set the order status to "Confirmed"? </DialogContentText> </DialogContent> <DialogActions> <Button onClick={handleClose} color="primary"> No </Button> <Button onClick={handleClose} color="primary"> Yes </Button> </DialogActions> </Dialog>
Material-UI: You have provided .., but could not. Try this codesandbox.io/s/material-demo-forked-0qg42?file=/demo.js And check MaterialUI Select set value is always out of range