/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/data/material/components/selects/DialogSelect.js
85 строк
3 KB
Jan Potoms
[docs] Use `React.useId()` for demo IDs (#48300)
19 апр 2026, 13:10
Не верифицирован
19 апр 2026, 13:10
107f22c
Код
Авторство
О чём код?
import * as React from 'react'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Dialog from '@mui/material/Dialog'; import DialogActions from '@mui/material/DialogActions'; import DialogContent from '@mui/material/DialogContent'; import DialogTitle from '@mui/material/DialogTitle'; import InputLabel from '@mui/material/InputLabel'; import OutlinedInput from '@mui/material/OutlinedInput'; import MenuItem from '@mui/material/MenuItem'; import FormControl from '@mui/material/FormControl'; import Select from '@mui/material/Select'; export default function DialogSelect() { const nativeId = React.useId(); const selectId = React.useId(); const [open, setOpen] = React.useState(false); const [age, setAge] = React.useState(''); const handleChange = (event) => { setAge(Number(event.target.value) || ''); }; const handleClickOpen = () => { setOpen(true); }; const handleDialogClose = (_event, reason) => { if (!['backdropClick', 'escapeKeyDown'].includes(reason)) { setOpen(false); } }; const handleActionButtonClick = () => { setOpen(false); }; return ( <div> <Button onClick={handleClickOpen}>Open select dialog</Button> <Dialog open={open} onClose={handleDialogClose}> <DialogTitle>Fill the form</DialogTitle> <DialogContent> <Box component="form" sx={{ display: 'flex', flexWrap: 'wrap' }}> <FormControl sx={{ m: 1, minWidth: 120 }}> <InputLabel htmlFor={`${nativeId}-select`}>Age</InputLabel> <Select native value={age} onChange={handleChange} input={<OutlinedInput label="Age" id={`${nativeId}-select`} />} > <option aria-label="None" value="" /> <option value={10}>Ten</option> <option value={20}>Twenty</option> <option value={30}>Thirty</option> </Select> </FormControl> <FormControl sx={{ m: 1, minWidth: 120 }}> <InputLabel id={`${selectId}-label`}>Age</InputLabel> <Select labelId={`${selectId}-label`} id={`${selectId}-select`} value={age} onChange={handleChange} input={<OutlinedInput label="Age" />} > <MenuItem value=""> <em>None</em> </MenuItem> <MenuItem value={10}>Ten</MenuItem> <MenuItem value={20}>Twenty</MenuItem> <MenuItem value={30}>Thirty</MenuItem> </Select> </FormControl> </Box> </DialogContent> <DialogActions> <Button onClick={handleActionButtonClick}>Cancel</Button> <Button onClick={handleActionButtonClick}>Ok</Button> </DialogActions> </Dialog> </div> ); }