/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/data/material/components/progress/LinearWithAriaValueText.js
77 строк
2 KB
Silviu Alexandru Avram
[circularprogress][linearprogress] Improve accessibility (#48172)
15 апр 2026, 13:29
Не верифицирован
15 апр 2026, 13:29
529b113
Код
Авторство
О чём код?
import * as React from 'react'; import PropTypes from 'prop-types'; import LinearProgress from '@mui/material/LinearProgress'; import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; function LinearProgressWithLabelAndValue({ max, min, value, ...rest }) { const progressText = `Elevator at floor ${value} out of ${max}.`; const progressId = React.useId(); return ( <div> <Typography id={progressId} variant="body2" color="text.secondary" sx={{ mr: 1 }} > Elevator status </Typography> <Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ width: '100%', mr: 1 }}> <LinearProgress variant="determinate" aria-labelledby={progressId} aria-valuetext={progressText} min={min} max={max} value={value} {...rest} /> </Box> <Box sx={{ whiteSpace: 'nowrap' }}> <Typography variant="body2" sx={{ color: 'text.secondary' }}> {progressText} </Typography> </Box> </Box> </div> ); } LinearProgressWithLabelAndValue.propTypes = { /** * The maximum value for the progress indicator for the determinate and buffer variants. * @default 100 */ max: PropTypes.number.isRequired, /** * The minimum value for the progress indicator for the determinate and buffer variants. * @default 0 */ min: PropTypes.number.isRequired, /** * The value of the progress indicator for the determinate and buffer variants. * Value between `min` and `max`. */ value: PropTypes.number.isRequired, }; export default function LinearWithAriaValueText() { const [progress, setProgress] = React.useState(1); React.useEffect(() => { const timer = setInterval(() => { setProgress((prevProgress) => (prevProgress >= 10 ? 1 : prevProgress + 1)); }, 800); return () => { clearInterval(timer); }; }, []); return ( <Box sx={{ width: '100%' }}> <LinearProgressWithLabelAndValue value={progress} min={1} max={10} /> </Box> ); }