index
int64 0
0
| repo_id
stringlengths 16
181
| file_path
stringlengths 28
270
| content
stringlengths 1
11.6M
| __index_level_0__
int64 0
10k
|
---|---|---|---|---|
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularUnderLoad.tsx.preview | <CircularProgress disableShrink /> | 2,800 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularWithValueLabel.js | import * as React from 'react';
import PropTypes from 'prop-types';
import CircularProgress from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
function CircularProgressWithLabel(props) {
return (
<Box sx={{ position: 'relative', display: 'inline-flex' }}>
<CircularProgress variant="determinate" {...props} />
<Box
sx={{
top: 0,
left: 0,
bottom: 0,
right: 0,
position: 'absolute',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Typography variant="caption" component="div" color="text.secondary">
{`${Math.round(props.value)}%`}
</Typography>
</Box>
</Box>
);
}
CircularProgressWithLabel.propTypes = {
/**
* The value of the progress indicator for the determinate variant.
* Value between 0 and 100.
* @default 0
*/
value: PropTypes.number.isRequired,
};
export default function CircularWithValueLabel() {
const [progress, setProgress] = React.useState(10);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);
return <CircularProgressWithLabel value={progress} />;
}
| 2,801 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularWithValueLabel.tsx | import * as React from 'react';
import CircularProgress, {
CircularProgressProps,
} from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
function CircularProgressWithLabel(
props: CircularProgressProps & { value: number },
) {
return (
<Box sx={{ position: 'relative', display: 'inline-flex' }}>
<CircularProgress variant="determinate" {...props} />
<Box
sx={{
top: 0,
left: 0,
bottom: 0,
right: 0,
position: 'absolute',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Typography
variant="caption"
component="div"
color="text.secondary"
>{`${Math.round(props.value)}%`}</Typography>
</Box>
</Box>
);
}
export default function CircularWithValueLabel() {
const [progress, setProgress] = React.useState(10);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);
return <CircularProgressWithLabel value={progress} />;
}
| 2,802 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularWithValueLabel.tsx.preview | <CircularProgressWithLabel value={progress} /> | 2,803 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CustomizedProgressBars.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import CircularProgress, {
circularProgressClasses,
} from '@mui/material/CircularProgress';
import LinearProgress, { linearProgressClasses } from '@mui/material/LinearProgress';
const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({
height: 10,
borderRadius: 5,
[`&.${linearProgressClasses.colorPrimary}`]: {
backgroundColor: theme.palette.grey[theme.palette.mode === 'light' ? 200 : 800],
},
[`& .${linearProgressClasses.bar}`]: {
borderRadius: 5,
backgroundColor: theme.palette.mode === 'light' ? '#1a90ff' : '#308fe8',
},
}));
// Inspired by the former Facebook spinners.
function FacebookCircularProgress(props) {
return (
<Box sx={{ position: 'relative' }}>
<CircularProgress
variant="determinate"
sx={{
color: (theme) =>
theme.palette.grey[theme.palette.mode === 'light' ? 200 : 800],
}}
size={40}
thickness={4}
{...props}
value={100}
/>
<CircularProgress
variant="indeterminate"
disableShrink
sx={{
color: (theme) => (theme.palette.mode === 'light' ? '#1a90ff' : '#308fe8'),
animationDuration: '550ms',
position: 'absolute',
left: 0,
[`& .${circularProgressClasses.circle}`]: {
strokeLinecap: 'round',
},
}}
size={40}
thickness={4}
{...props}
/>
</Box>
);
}
export default function CustomizedProgressBars() {
return (
<Box sx={{ flexGrow: 1 }}>
<FacebookCircularProgress />
<br />
<BorderLinearProgress variant="determinate" value={50} />
</Box>
);
}
| 2,804 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CustomizedProgressBars.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import CircularProgress, {
circularProgressClasses,
CircularProgressProps,
} from '@mui/material/CircularProgress';
import LinearProgress, { linearProgressClasses } from '@mui/material/LinearProgress';
const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({
height: 10,
borderRadius: 5,
[`&.${linearProgressClasses.colorPrimary}`]: {
backgroundColor: theme.palette.grey[theme.palette.mode === 'light' ? 200 : 800],
},
[`& .${linearProgressClasses.bar}`]: {
borderRadius: 5,
backgroundColor: theme.palette.mode === 'light' ? '#1a90ff' : '#308fe8',
},
}));
// Inspired by the former Facebook spinners.
function FacebookCircularProgress(props: CircularProgressProps) {
return (
<Box sx={{ position: 'relative' }}>
<CircularProgress
variant="determinate"
sx={{
color: (theme) =>
theme.palette.grey[theme.palette.mode === 'light' ? 200 : 800],
}}
size={40}
thickness={4}
{...props}
value={100}
/>
<CircularProgress
variant="indeterminate"
disableShrink
sx={{
color: (theme) => (theme.palette.mode === 'light' ? '#1a90ff' : '#308fe8'),
animationDuration: '550ms',
position: 'absolute',
left: 0,
[`& .${circularProgressClasses.circle}`]: {
strokeLinecap: 'round',
},
}}
size={40}
thickness={4}
{...props}
/>
</Box>
);
}
export default function CustomizedProgressBars() {
return (
<Box sx={{ flexGrow: 1 }}>
<FacebookCircularProgress />
<br />
<BorderLinearProgress variant="determinate" value={50} />
</Box>
);
}
| 2,805 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/CustomizedProgressBars.tsx.preview | <FacebookCircularProgress />
<br />
<BorderLinearProgress variant="determinate" value={50} /> | 2,806 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/DelayingAppearance.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Fade from '@mui/material/Fade';
import Button from '@mui/material/Button';
import CircularProgress from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';
export default function DelayingAppearance() {
const [loading, setLoading] = React.useState(false);
const [query, setQuery] = React.useState('idle');
const timerRef = React.useRef();
React.useEffect(
() => () => {
clearTimeout(timerRef.current);
},
[],
);
const handleClickLoading = () => {
setLoading((prevLoading) => !prevLoading);
};
const handleClickQuery = () => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
if (query !== 'idle') {
setQuery('idle');
return;
}
setQuery('progress');
timerRef.current = window.setTimeout(() => {
setQuery('success');
}, 2000);
};
return (
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<Box sx={{ height: 40 }}>
<Fade
in={loading}
style={{
transitionDelay: loading ? '800ms' : '0ms',
}}
unmountOnExit
>
<CircularProgress />
</Fade>
</Box>
<Button onClick={handleClickLoading} sx={{ m: 2 }}>
{loading ? 'Stop loading' : 'Loading'}
</Button>
<Box sx={{ height: 40 }}>
{query === 'success' ? (
<Typography>Success!</Typography>
) : (
<Fade
in={query === 'progress'}
style={{
transitionDelay: query === 'progress' ? '800ms' : '0ms',
}}
unmountOnExit
>
<CircularProgress />
</Fade>
)}
</Box>
<Button onClick={handleClickQuery} sx={{ m: 2 }}>
{query !== 'idle' ? 'Reset' : 'Simulate a load'}
</Button>
</Box>
);
}
| 2,807 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/DelayingAppearance.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Fade from '@mui/material/Fade';
import Button from '@mui/material/Button';
import CircularProgress from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';
export default function DelayingAppearance() {
const [loading, setLoading] = React.useState(false);
const [query, setQuery] = React.useState('idle');
const timerRef = React.useRef<number>();
React.useEffect(
() => () => {
clearTimeout(timerRef.current);
},
[],
);
const handleClickLoading = () => {
setLoading((prevLoading) => !prevLoading);
};
const handleClickQuery = () => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
if (query !== 'idle') {
setQuery('idle');
return;
}
setQuery('progress');
timerRef.current = window.setTimeout(() => {
setQuery('success');
}, 2000);
};
return (
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<Box sx={{ height: 40 }}>
<Fade
in={loading}
style={{
transitionDelay: loading ? '800ms' : '0ms',
}}
unmountOnExit
>
<CircularProgress />
</Fade>
</Box>
<Button onClick={handleClickLoading} sx={{ m: 2 }}>
{loading ? 'Stop loading' : 'Loading'}
</Button>
<Box sx={{ height: 40 }}>
{query === 'success' ? (
<Typography>Success!</Typography>
) : (
<Fade
in={query === 'progress'}
style={{
transitionDelay: query === 'progress' ? '800ms' : '0ms',
}}
unmountOnExit
>
<CircularProgress />
</Fade>
)}
</Box>
<Button onClick={handleClickQuery} sx={{ m: 2 }}>
{query !== 'idle' ? 'Reset' : 'Simulate a load'}
</Button>
</Box>
);
}
| 2,808 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearBuffer.js | import * as React from 'react';
import Box from '@mui/material/Box';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearBuffer() {
const [progress, setProgress] = React.useState(0);
const [buffer, setBuffer] = React.useState(10);
const progressRef = React.useRef(() => {});
React.useEffect(() => {
progressRef.current = () => {
if (progress > 100) {
setProgress(0);
setBuffer(10);
} else {
const diff = Math.random() * 10;
const diff2 = Math.random() * 10;
setProgress(progress + diff);
setBuffer(progress + diff + diff2);
}
};
});
React.useEffect(() => {
const timer = setInterval(() => {
progressRef.current();
}, 500);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ width: '100%' }}>
<LinearProgress variant="buffer" value={progress} valueBuffer={buffer} />
</Box>
);
}
| 2,809 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearBuffer.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearBuffer() {
const [progress, setProgress] = React.useState(0);
const [buffer, setBuffer] = React.useState(10);
const progressRef = React.useRef(() => {});
React.useEffect(() => {
progressRef.current = () => {
if (progress > 100) {
setProgress(0);
setBuffer(10);
} else {
const diff = Math.random() * 10;
const diff2 = Math.random() * 10;
setProgress(progress + diff);
setBuffer(progress + diff + diff2);
}
};
});
React.useEffect(() => {
const timer = setInterval(() => {
progressRef.current();
}, 500);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ width: '100%' }}>
<LinearProgress variant="buffer" value={progress} valueBuffer={buffer} />
</Box>
);
}
| 2,810 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearBuffer.tsx.preview | <LinearProgress variant="buffer" value={progress} valueBuffer={buffer} /> | 2,811 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearColor.js | import * as React from 'react';
import Stack from '@mui/material/Stack';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearColor() {
return (
<Stack sx={{ width: '100%', color: 'grey.500' }} spacing={2}>
<LinearProgress color="secondary" />
<LinearProgress color="success" />
<LinearProgress color="inherit" />
</Stack>
);
}
| 2,812 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearColor.tsx | import * as React from 'react';
import Stack from '@mui/material/Stack';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearColor() {
return (
<Stack sx={{ width: '100%', color: 'grey.500' }} spacing={2}>
<LinearProgress color="secondary" />
<LinearProgress color="success" />
<LinearProgress color="inherit" />
</Stack>
);
}
| 2,813 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearColor.tsx.preview | <LinearProgress color="secondary" />
<LinearProgress color="success" />
<LinearProgress color="inherit" /> | 2,814 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearDeterminate.js | import * as React from 'react';
import Box from '@mui/material/Box';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearDeterminate() {
const [progress, setProgress] = React.useState(0);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((oldProgress) => {
if (oldProgress === 100) {
return 0;
}
const diff = Math.random() * 10;
return Math.min(oldProgress + diff, 100);
});
}, 500);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ width: '100%' }}>
<LinearProgress variant="determinate" value={progress} />
</Box>
);
}
| 2,815 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearDeterminate.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearDeterminate() {
const [progress, setProgress] = React.useState(0);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((oldProgress) => {
if (oldProgress === 100) {
return 0;
}
const diff = Math.random() * 10;
return Math.min(oldProgress + diff, 100);
});
}, 500);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ width: '100%' }}>
<LinearProgress variant="determinate" value={progress} />
</Box>
);
}
| 2,816 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearDeterminate.tsx.preview | <LinearProgress variant="determinate" value={progress} /> | 2,817 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearIndeterminate.js | import * as React from 'react';
import Box from '@mui/material/Box';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearIndeterminate() {
return (
<Box sx={{ width: '100%' }}>
<LinearProgress />
</Box>
);
}
| 2,818 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearIndeterminate.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import LinearProgress from '@mui/material/LinearProgress';
export default function LinearIndeterminate() {
return (
<Box sx={{ width: '100%' }}>
<LinearProgress />
</Box>
);
}
| 2,819 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearIndeterminate.tsx.preview | <LinearProgress /> | 2,820 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearWithValueLabel.js | 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 LinearProgressWithLabel(props) {
return (
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Box sx={{ width: '100%', mr: 1 }}>
<LinearProgress variant="determinate" {...props} />
</Box>
<Box sx={{ minWidth: 35 }}>
<Typography variant="body2" color="text.secondary">{`${Math.round(
props.value,
)}%`}</Typography>
</Box>
</Box>
);
}
LinearProgressWithLabel.propTypes = {
/**
* The value of the progress indicator for the determinate and buffer variants.
* Value between 0 and 100.
*/
value: PropTypes.number.isRequired,
};
export default function LinearWithValueLabel() {
const [progress, setProgress] = React.useState(10);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 10 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ width: '100%' }}>
<LinearProgressWithLabel value={progress} />
</Box>
);
}
| 2,821 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearWithValueLabel.tsx | import * as React from 'react';
import LinearProgress, { LinearProgressProps } from '@mui/material/LinearProgress';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
function LinearProgressWithLabel(props: LinearProgressProps & { value: number }) {
return (
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Box sx={{ width: '100%', mr: 1 }}>
<LinearProgress variant="determinate" {...props} />
</Box>
<Box sx={{ minWidth: 35 }}>
<Typography variant="body2" color="text.secondary">{`${Math.round(
props.value,
)}%`}</Typography>
</Box>
</Box>
);
}
export default function LinearWithValueLabel() {
const [progress, setProgress] = React.useState(10);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 10 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ width: '100%' }}>
<LinearProgressWithLabel value={progress} />
</Box>
);
}
| 2,822 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/LinearWithValueLabel.tsx.preview | <LinearProgressWithLabel value={progress} /> | 2,823 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/progress/progress.md | ---
productId: material-ui
title: Circular, Linear progress React components
components: CircularProgress, LinearProgress
githubLabel: 'component: progress'
materialDesign: https://m2.material.io/components/progress-indicators
---
# Progress
<p class="description">Progress indicators commonly known as spinners, express an unspecified wait time or display the length of a process.</p>
Progress indicators inform users about the status of ongoing processes, such as loading an app, submitting a form, or saving updates.
- **Determinate** indicators display how long an operation will take.
- **Indeterminate** indicators visualize an unspecified wait time.
The animations of the components rely on CSS as much as possible to work even before the JavaScript is loaded.
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Circular
### Circular indeterminate
{{"demo": "CircularIndeterminate.js"}}
### Circular color
{{"demo": "CircularColor.js"}}
### Circular determinate
{{"demo": "CircularDeterminate.js"}}
### Interactive integration
{{"demo": "CircularIntegration.js"}}
### Circular with label
{{"demo": "CircularWithValueLabel.js"}}
## Linear
### Linear indeterminate
{{"demo": "LinearIndeterminate.js"}}
### Linear color
{{"demo": "LinearColor.js"}}
### Linear determinate
{{"demo": "LinearDeterminate.js"}}
### Linear buffer
{{"demo": "LinearBuffer.js"}}
### Linear with label
{{"demo": "LinearWithValueLabel.js"}}
## Non-standard ranges
The progress components accept a value in the range 0 - 100. This simplifies things for screen-reader users, where these are the default min / max values. Sometimes, however, you might be working with a data source where the values fall outside this range. Here's how you can easily transform a value in any range to a scale of 0 - 100:
```jsx
// MIN = Minimum expected value
// MAX = Maximum expected value
// Function to normalise the values (MIN / MAX could be integrated)
const normalise = (value) => ((value - MIN) * 100) / (MAX - MIN);
// Example component that utilizes the `normalise` function at the point of render.
function Progress(props) {
return (
<React.Fragment>
<CircularProgress variant="determinate" value={normalise(props.value)} />
<LinearProgress variant="determinate" value={normalise(props.value)} />
</React.Fragment>
);
}
```
## Customization
Here are some examples of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
{{"demo": "CustomizedProgressBars.js", "defaultCodeOpen": false}}
## Delaying appearance
There are [3 important limits](https://www.nngroup.com/articles/response-times-3-important-limits/) to know around response time.
The ripple effect of the `ButtonBase` component ensures that the user feels that the system is reacting instantaneously.
Normally, no special feedback is necessary during delays of more than 0.1 but less than 1.0 second.
After 1.0 second, you can display a loader to keep user's flow of thought uninterrupted.
{{"demo": "DelayingAppearance.js"}}
## Limitations
### High CPU load
Under heavy load, you might lose the stroke dash animation or see random `CircularProgress` ring widths.
You should run processor intensive operations in a web worker or by batch in order not to block the main rendering thread.

When it's not possible, you can leverage the `disableShrink` prop to mitigate the issue.
See [this issue](https://github.com/mui/material-ui/issues/10327).
{{"demo": "CircularUnderLoad.js"}}
### High frequency updates
The `LinearProgress` uses a transition on the CSS transform property to provide a smooth update between different values.
The default transition duration is 200ms.
In the event a parent component updates the `value` prop too quickly, you will at least experience a 200ms delay between the re-render and the progress bar fully updated.
If you need to perform 30 re-renders per second or more, we recommend disabling the transition:
```css
.MuiLinearProgress-bar {
transition: none;
}
```
### IE 11
The circular progress component animation on IE 11 is degraded.
The stroke dash animation is not working (equivalent to `disableShrink`) and the circular animation wobbles.
You can solve the latter with:
```css
.MuiCircularProgress-indeterminate {
animation: circular-rotate 1.4s linear infinite;
}
@keyframes circular-rotate {
0% {
transform: rotate(0deg);
/* Fix IE11 wobbly */
transform-origin: 50% 50%;
}
100% {
transform: rotate(360deg);
}
}
```
| 2,824 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ColorRadioButtons.js | import * as React from 'react';
import { pink } from '@mui/material/colors';
import Radio from '@mui/material/Radio';
export default function ColorRadioButtons() {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event) => {
setSelectedValue(event.target.value);
};
const controlProps = (item) => ({
checked: selectedValue === item,
onChange: handleChange,
value: item,
name: 'color-radio-button-demo',
inputProps: { 'aria-label': item },
});
return (
<div>
<Radio {...controlProps('a')} />
<Radio {...controlProps('b')} color="secondary" />
<Radio {...controlProps('c')} color="success" />
<Radio {...controlProps('d')} color="default" />
<Radio
{...controlProps('e')}
sx={{
color: pink[800],
'&.Mui-checked': {
color: pink[600],
},
}}
/>
</div>
);
}
| 2,825 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ColorRadioButtons.tsx | import * as React from 'react';
import { pink } from '@mui/material/colors';
import Radio from '@mui/material/Radio';
export default function ColorRadioButtons() {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedValue(event.target.value);
};
const controlProps = (item: string) => ({
checked: selectedValue === item,
onChange: handleChange,
value: item,
name: 'color-radio-button-demo',
inputProps: { 'aria-label': item },
});
return (
<div>
<Radio {...controlProps('a')} />
<Radio {...controlProps('b')} color="secondary" />
<Radio {...controlProps('c')} color="success" />
<Radio {...controlProps('d')} color="default" />
<Radio
{...controlProps('e')}
sx={{
color: pink[800],
'&.Mui-checked': {
color: pink[600],
},
}}
/>
</div>
);
}
| 2,826 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ColorRadioButtons.tsx.preview | <Radio {...controlProps('a')} />
<Radio {...controlProps('b')} color="secondary" />
<Radio {...controlProps('c')} color="success" />
<Radio {...controlProps('d')} color="default" />
<Radio
{...controlProps('e')}
sx={{
color: pink[800],
'&.Mui-checked': {
color: pink[600],
},
}}
/> | 2,827 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ControlledRadioButtonsGroup.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function ControlledRadioButtonsGroup() {
const [value, setValue] = React.useState('female');
const handleChange = (event) => {
setValue(event.target.value);
};
return (
<FormControl>
<FormLabel id="demo-controlled-radio-buttons-group">Gender</FormLabel>
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
name="controlled-radio-buttons-group"
value={value}
onChange={handleChange}
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
</RadioGroup>
</FormControl>
);
}
| 2,828 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ControlledRadioButtonsGroup.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function ControlledRadioButtonsGroup() {
const [value, setValue] = React.useState('female');
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue((event.target as HTMLInputElement).value);
};
return (
<FormControl>
<FormLabel id="demo-controlled-radio-buttons-group">Gender</FormLabel>
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
name="controlled-radio-buttons-group"
value={value}
onChange={handleChange}
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
</RadioGroup>
</FormControl>
);
}
| 2,829 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ControlledRadioButtonsGroup.tsx.preview | <FormControl>
<FormLabel id="demo-controlled-radio-buttons-group">Gender</FormLabel>
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
name="controlled-radio-buttons-group"
value={value}
onChange={handleChange}
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
</RadioGroup>
</FormControl> | 2,830 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/CustomizedRadios.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
const BpIcon = styled('span')(({ theme }) => ({
borderRadius: '50%',
width: 16,
height: 16,
boxShadow:
theme.palette.mode === 'dark'
? '0 0 0 1px rgb(16 22 26 / 40%)'
: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)',
backgroundColor: theme.palette.mode === 'dark' ? '#394b59' : '#f5f8fa',
backgroundImage:
theme.palette.mode === 'dark'
? 'linear-gradient(180deg,hsla(0,0%,100%,.05),hsla(0,0%,100%,0))'
: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))',
'.Mui-focusVisible &': {
outline: '2px auto rgba(19,124,189,.6)',
outlineOffset: 2,
},
'input:hover ~ &': {
backgroundColor: theme.palette.mode === 'dark' ? '#30404d' : '#ebf1f5',
},
'input:disabled ~ &': {
boxShadow: 'none',
background:
theme.palette.mode === 'dark' ? 'rgba(57,75,89,.5)' : 'rgba(206,217,224,.5)',
},
}));
const BpCheckedIcon = styled(BpIcon)({
backgroundColor: '#137cbd',
backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))',
'&:before': {
display: 'block',
width: 16,
height: 16,
backgroundImage: 'radial-gradient(#fff,#fff 28%,transparent 32%)',
content: '""',
},
'input:hover ~ &': {
backgroundColor: '#106ba3',
},
});
// Inspired by blueprintjs
function BpRadio(props) {
return (
<Radio
disableRipple
color="default"
checkedIcon={<BpCheckedIcon />}
icon={<BpIcon />}
{...props}
/>
);
}
export default function CustomizedRadios() {
return (
<FormControl>
<FormLabel id="demo-customized-radios">Gender</FormLabel>
<RadioGroup
defaultValue="female"
aria-labelledby="demo-customized-radios"
name="customized-radios"
>
<FormControlLabel value="female" control={<BpRadio />} label="Female" />
<FormControlLabel value="male" control={<BpRadio />} label="Male" />
<FormControlLabel value="other" control={<BpRadio />} label="Other" />
<FormControlLabel
value="disabled"
disabled
control={<BpRadio />}
label="(Disabled option)"
/>
</RadioGroup>
</FormControl>
);
}
| 2,831 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/CustomizedRadios.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Radio, { RadioProps } from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
const BpIcon = styled('span')(({ theme }) => ({
borderRadius: '50%',
width: 16,
height: 16,
boxShadow:
theme.palette.mode === 'dark'
? '0 0 0 1px rgb(16 22 26 / 40%)'
: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)',
backgroundColor: theme.palette.mode === 'dark' ? '#394b59' : '#f5f8fa',
backgroundImage:
theme.palette.mode === 'dark'
? 'linear-gradient(180deg,hsla(0,0%,100%,.05),hsla(0,0%,100%,0))'
: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))',
'.Mui-focusVisible &': {
outline: '2px auto rgba(19,124,189,.6)',
outlineOffset: 2,
},
'input:hover ~ &': {
backgroundColor: theme.palette.mode === 'dark' ? '#30404d' : '#ebf1f5',
},
'input:disabled ~ &': {
boxShadow: 'none',
background:
theme.palette.mode === 'dark' ? 'rgba(57,75,89,.5)' : 'rgba(206,217,224,.5)',
},
}));
const BpCheckedIcon = styled(BpIcon)({
backgroundColor: '#137cbd',
backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))',
'&:before': {
display: 'block',
width: 16,
height: 16,
backgroundImage: 'radial-gradient(#fff,#fff 28%,transparent 32%)',
content: '""',
},
'input:hover ~ &': {
backgroundColor: '#106ba3',
},
});
// Inspired by blueprintjs
function BpRadio(props: RadioProps) {
return (
<Radio
disableRipple
color="default"
checkedIcon={<BpCheckedIcon />}
icon={<BpIcon />}
{...props}
/>
);
}
export default function CustomizedRadios() {
return (
<FormControl>
<FormLabel id="demo-customized-radios">Gender</FormLabel>
<RadioGroup
defaultValue="female"
aria-labelledby="demo-customized-radios"
name="customized-radios"
>
<FormControlLabel value="female" control={<BpRadio />} label="Female" />
<FormControlLabel value="male" control={<BpRadio />} label="Male" />
<FormControlLabel value="other" control={<BpRadio />} label="Other" />
<FormControlLabel
value="disabled"
disabled
control={<BpRadio />}
label="(Disabled option)"
/>
</RadioGroup>
</FormControl>
);
}
| 2,832 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ErrorRadios.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
import FormLabel from '@mui/material/FormLabel';
import Button from '@mui/material/Button';
export default function ErrorRadios() {
const [value, setValue] = React.useState('');
const [error, setError] = React.useState(false);
const [helperText, setHelperText] = React.useState('Choose wisely');
const handleRadioChange = (event) => {
setValue(event.target.value);
setHelperText(' ');
setError(false);
};
const handleSubmit = (event) => {
event.preventDefault();
if (value === 'best') {
setHelperText('You got it!');
setError(false);
} else if (value === 'worst') {
setHelperText('Sorry, wrong answer!');
setError(true);
} else {
setHelperText('Please select an option.');
setError(true);
}
};
return (
<form onSubmit={handleSubmit}>
<FormControl sx={{ m: 3 }} error={error} variant="standard">
<FormLabel id="demo-error-radios">Pop quiz: MUI is...</FormLabel>
<RadioGroup
aria-labelledby="demo-error-radios"
name="quiz"
value={value}
onChange={handleRadioChange}
>
<FormControlLabel value="best" control={<Radio />} label="The best!" />
<FormControlLabel value="worst" control={<Radio />} label="The worst." />
</RadioGroup>
<FormHelperText>{helperText}</FormHelperText>
<Button sx={{ mt: 1, mr: 1 }} type="submit" variant="outlined">
Check Answer
</Button>
</FormControl>
</form>
);
}
| 2,833 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/ErrorRadios.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
import FormLabel from '@mui/material/FormLabel';
import Button from '@mui/material/Button';
export default function ErrorRadios() {
const [value, setValue] = React.useState('');
const [error, setError] = React.useState(false);
const [helperText, setHelperText] = React.useState('Choose wisely');
const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue((event.target as HTMLInputElement).value);
setHelperText(' ');
setError(false);
};
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (value === 'best') {
setHelperText('You got it!');
setError(false);
} else if (value === 'worst') {
setHelperText('Sorry, wrong answer!');
setError(true);
} else {
setHelperText('Please select an option.');
setError(true);
}
};
return (
<form onSubmit={handleSubmit}>
<FormControl sx={{ m: 3 }} error={error} variant="standard">
<FormLabel id="demo-error-radios">Pop quiz: MUI is...</FormLabel>
<RadioGroup
aria-labelledby="demo-error-radios"
name="quiz"
value={value}
onChange={handleRadioChange}
>
<FormControlLabel value="best" control={<Radio />} label="The best!" />
<FormControlLabel value="worst" control={<Radio />} label="The worst." />
</RadioGroup>
<FormHelperText>{helperText}</FormHelperText>
<Button sx={{ mt: 1, mr: 1 }} type="submit" variant="outlined">
Check Answer
</Button>
</FormControl>
</form>
);
}
| 2,834 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/FormControlLabelPlacement.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function FormControlLabelPlacement() {
return (
<FormControl>
<FormLabel id="demo-form-control-label-placement">Label placement</FormLabel>
<RadioGroup
row
aria-labelledby="demo-form-control-label-placement"
name="position"
defaultValue="top"
>
<FormControlLabel
value="top"
control={<Radio />}
label="Top"
labelPlacement="top"
/>
<FormControlLabel
value="start"
control={<Radio />}
label="Start"
labelPlacement="start"
/>
<FormControlLabel
value="bottom"
control={<Radio />}
label="Bottom"
labelPlacement="bottom"
/>
<FormControlLabel value="end" control={<Radio />} label="End" />
</RadioGroup>
</FormControl>
);
}
| 2,835 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/FormControlLabelPlacement.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function FormControlLabelPlacement() {
return (
<FormControl>
<FormLabel id="demo-form-control-label-placement">Label placement</FormLabel>
<RadioGroup
row
aria-labelledby="demo-form-control-label-placement"
name="position"
defaultValue="top"
>
<FormControlLabel
value="top"
control={<Radio />}
label="Top"
labelPlacement="top"
/>
<FormControlLabel
value="start"
control={<Radio />}
label="Start"
labelPlacement="start"
/>
<FormControlLabel
value="bottom"
control={<Radio />}
label="Bottom"
labelPlacement="bottom"
/>
<FormControlLabel value="end" control={<Radio />} label="End" />
</RadioGroup>
</FormControl>
);
}
| 2,836 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RadioButtons.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
export default function RadioButtons() {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event) => {
setSelectedValue(event.target.value);
};
return (
<div>
<Radio
checked={selectedValue === 'a'}
onChange={handleChange}
value="a"
name="radio-buttons"
inputProps={{ 'aria-label': 'A' }}
/>
<Radio
checked={selectedValue === 'b'}
onChange={handleChange}
value="b"
name="radio-buttons"
inputProps={{ 'aria-label': 'B' }}
/>
</div>
);
}
| 2,837 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RadioButtons.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
export default function RadioButtons() {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedValue(event.target.value);
};
return (
<div>
<Radio
checked={selectedValue === 'a'}
onChange={handleChange}
value="a"
name="radio-buttons"
inputProps={{ 'aria-label': 'A' }}
/>
<Radio
checked={selectedValue === 'b'}
onChange={handleChange}
value="b"
name="radio-buttons"
inputProps={{ 'aria-label': 'B' }}
/>
</div>
);
}
| 2,838 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RadioButtons.tsx.preview | <Radio
checked={selectedValue === 'a'}
onChange={handleChange}
value="a"
name="radio-buttons"
inputProps={{ 'aria-label': 'A' }}
/>
<Radio
checked={selectedValue === 'b'}
onChange={handleChange}
value="b"
name="radio-buttons"
inputProps={{ 'aria-label': 'B' }}
/> | 2,839 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RadioButtonsGroup.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function RadioButtonsGroup() {
return (
<FormControl>
<FormLabel id="demo-radio-buttons-group-label">Gender</FormLabel>
<RadioGroup
aria-labelledby="demo-radio-buttons-group-label"
defaultValue="female"
name="radio-buttons-group"
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
</RadioGroup>
</FormControl>
);
}
| 2,840 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RadioButtonsGroup.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function RadioButtonsGroup() {
return (
<FormControl>
<FormLabel id="demo-radio-buttons-group-label">Gender</FormLabel>
<RadioGroup
aria-labelledby="demo-radio-buttons-group-label"
defaultValue="female"
name="radio-buttons-group"
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
</RadioGroup>
</FormControl>
);
}
| 2,841 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RadioButtonsGroup.tsx.preview | <FormControl>
<FormLabel id="demo-radio-buttons-group-label">Gender</FormLabel>
<RadioGroup
aria-labelledby="demo-radio-buttons-group-label"
defaultValue="female"
name="radio-buttons-group"
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
</RadioGroup>
</FormControl> | 2,842 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RowRadioButtonsGroup.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function RowRadioButtonsGroup() {
return (
<FormControl>
<FormLabel id="demo-row-radio-buttons-group-label">Gender</FormLabel>
<RadioGroup
row
aria-labelledby="demo-row-radio-buttons-group-label"
name="row-radio-buttons-group"
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
<FormControlLabel
value="disabled"
disabled
control={<Radio />}
label="other"
/>
</RadioGroup>
</FormControl>
);
}
| 2,843 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/RowRadioButtonsGroup.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
export default function RowRadioButtonsGroup() {
return (
<FormControl>
<FormLabel id="demo-row-radio-buttons-group-label">Gender</FormLabel>
<RadioGroup
row
aria-labelledby="demo-row-radio-buttons-group-label"
name="row-radio-buttons-group"
>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
<FormControlLabel
value="disabled"
disabled
control={<Radio />}
label="other"
/>
</RadioGroup>
</FormControl>
);
}
| 2,844 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/SizeRadioButtons.js | import * as React from 'react';
import Radio from '@mui/material/Radio';
export default function SizeRadioButtons() {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event) => {
setSelectedValue(event.target.value);
};
const controlProps = (item) => ({
checked: selectedValue === item,
onChange: handleChange,
value: item,
name: 'size-radio-button-demo',
inputProps: { 'aria-label': item },
});
return (
<div>
<Radio {...controlProps('a')} size="small" />
<Radio {...controlProps('b')} />
<Radio
{...controlProps('c')}
sx={{
'& .MuiSvgIcon-root': {
fontSize: 28,
},
}}
/>
</div>
);
}
| 2,845 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/SizeRadioButtons.tsx | import * as React from 'react';
import Radio from '@mui/material/Radio';
export default function SizeRadioButtons() {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedValue(event.target.value);
};
const controlProps = (item: string) => ({
checked: selectedValue === item,
onChange: handleChange,
value: item,
name: 'size-radio-button-demo',
inputProps: { 'aria-label': item },
});
return (
<div>
<Radio {...controlProps('a')} size="small" />
<Radio {...controlProps('b')} />
<Radio
{...controlProps('c')}
sx={{
'& .MuiSvgIcon-root': {
fontSize: 28,
},
}}
/>
</div>
);
}
| 2,846 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/SizeRadioButtons.tsx.preview | <Radio {...controlProps('a')} size="small" />
<Radio {...controlProps('b')} />
<Radio
{...controlProps('c')}
sx={{
'& .MuiSvgIcon-root': {
fontSize: 28,
},
}}
/> | 2,847 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/UseRadioGroup.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import RadioGroup, { useRadioGroup } from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import Radio from '@mui/material/Radio';
const StyledFormControlLabel = styled((props) => <FormControlLabel {...props} />)(
({ theme, checked }) => ({
'.MuiFormControlLabel-label': checked && {
color: theme.palette.primary.main,
},
}),
);
function MyFormControlLabel(props) {
const radioGroup = useRadioGroup();
let checked = false;
if (radioGroup) {
checked = radioGroup.value === props.value;
}
return <StyledFormControlLabel checked={checked} {...props} />;
}
MyFormControlLabel.propTypes = {
/**
* The value of the component.
*/
value: PropTypes.any,
};
export default function UseRadioGroup() {
return (
<RadioGroup name="use-radio-group" defaultValue="first">
<MyFormControlLabel value="first" label="First" control={<Radio />} />
<MyFormControlLabel value="second" label="Second" control={<Radio />} />
</RadioGroup>
);
}
| 2,848 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/UseRadioGroup.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import RadioGroup, { useRadioGroup } from '@mui/material/RadioGroup';
import FormControlLabel, {
FormControlLabelProps,
} from '@mui/material/FormControlLabel';
import Radio from '@mui/material/Radio';
interface StyledFormControlLabelProps extends FormControlLabelProps {
checked: boolean;
}
const StyledFormControlLabel = styled((props: StyledFormControlLabelProps) => (
<FormControlLabel {...props} />
))(({ theme, checked }) => ({
'.MuiFormControlLabel-label': checked && {
color: theme.palette.primary.main,
},
}));
function MyFormControlLabel(props: FormControlLabelProps) {
const radioGroup = useRadioGroup();
let checked = false;
if (radioGroup) {
checked = radioGroup.value === props.value;
}
return <StyledFormControlLabel checked={checked} {...props} />;
}
export default function UseRadioGroup() {
return (
<RadioGroup name="use-radio-group" defaultValue="first">
<MyFormControlLabel value="first" label="First" control={<Radio />} />
<MyFormControlLabel value="second" label="Second" control={<Radio />} />
</RadioGroup>
);
}
| 2,849 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/UseRadioGroup.tsx.preview | <RadioGroup name="use-radio-group" defaultValue="first">
<MyFormControlLabel value="first" label="First" control={<Radio />} />
<MyFormControlLabel value="second" label="Second" control={<Radio />} />
</RadioGroup> | 2,850 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/radio-buttons/radio-buttons.md | ---
productId: material-ui
title: React Radio Group component
components: Radio, RadioGroup, FormControl, FormLabel, FormControlLabel
githubLabel: 'component: radio'
materialDesign: https://m2.material.io/components/selection-controls#radio-buttons
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/radio/
---
# Radio Group
<p class="description">The Radio Group allows the user to select one option from a set.</p>
Use radio buttons when the user needs to see all available options.
If available options can be collapsed, consider using a [Select component](/material-ui/react-select/) because it uses less space.
Radio buttons should have the most commonly used option selected by default.
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Radio group
`RadioGroup` is a helpful wrapper used to group `Radio` components that provides an easier API, and proper keyboard accessibility to the group.
{{"demo": "RadioButtonsGroup.js"}}
### Direction
To lay out the buttons horizontally, set the `row` prop:
{{"demo": "RowRadioButtonsGroup.js"}}
### Controlled
You can control the radio with the `value` and `onChange` props:
{{"demo": "ControlledRadioButtonsGroup.js"}}
## Standalone radio buttons
`Radio` can also be used standalone, without the RadioGroup wrapper.
{{"demo": "RadioButtons.js"}}
## Size
Use the `size` prop or customize the font size of the svg icons to change the size of the radios.
{{"demo": "SizeRadioButtons.js"}}
## Color
{{"demo": "ColorRadioButtons.js"}}
## Label placement
You can change the placement of the label with the `FormControlLabel` component's `labelPlacement` prop:
{{"demo": "FormControlLabelPlacement.js"}}
## Show error
In general, radio buttons should have a value selected by default. If this is not the case, you can display an error if no value is selected when the form is submitted:
{{"demo": "ErrorRadios.js"}}
## Customization
Here is an example of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
{{"demo": "CustomizedRadios.js"}}
## `useRadioGroup`
For advanced customization use cases, a `useRadioGroup()` hook is exposed.
It returns the context value of the parent radio group.
The Radio component uses this hook internally.
### API
```jsx
import { useRadioGroup } from '@mui/material/RadioGroup';
```
#### Returns
`value` (_object_):
- `value.name` (_string_ [optional]): The name used to reference the value of the control.
- `value.onChange` (_func_ [optional]): Callback fired when a radio button is selected.
- `value.value` (_any_ [optional]): Value of the selected radio button.
#### Example
{{"demo": "UseRadioGroup.js"}}
## When to use
- [Checkboxes vs. Radio Buttons](https://www.nngroup.com/articles/checkboxes-vs-radio-buttons/)
## Accessibility
(WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/radio/)
- All form controls should have labels, and this includes radio buttons, checkboxes, and switches. In most cases, this is done by using the `<label>` element ([FormControlLabel](/material-ui/api/form-control-label/)).
- When a label can't be used, it's necessary to add an attribute directly to the input component.
In this case, you can apply the additional attribute (e.g. `aria-label`, `aria-labelledby`, `title`) via the `inputProps` property.
```jsx
<Radio
value="radioA"
inputProps={{
'aria-label': 'Radio A',
}}
/>
```
| 2,851 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/BasicRating.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import Typography from '@mui/material/Typography';
export default function BasicRating() {
const [value, setValue] = React.useState(2);
return (
<Box
sx={{
'& > legend': { mt: 2 },
}}
>
<Typography component="legend">Controlled</Typography>
<Rating
name="simple-controlled"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
/>
<Typography component="legend">Read only</Typography>
<Rating name="read-only" value={value} readOnly />
<Typography component="legend">Disabled</Typography>
<Rating name="disabled" value={value} disabled />
<Typography component="legend">No rating given</Typography>
<Rating name="no-value" value={null} />
</Box>
);
}
| 2,852 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/BasicRating.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import Typography from '@mui/material/Typography';
export default function BasicRating() {
const [value, setValue] = React.useState<number | null>(2);
return (
<Box
sx={{
'& > legend': { mt: 2 },
}}
>
<Typography component="legend">Controlled</Typography>
<Rating
name="simple-controlled"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
/>
<Typography component="legend">Read only</Typography>
<Rating name="read-only" value={value} readOnly />
<Typography component="legend">Disabled</Typography>
<Rating name="disabled" value={value} disabled />
<Typography component="legend">No rating given</Typography>
<Rating name="no-value" value={null} />
</Box>
);
}
| 2,853 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/BasicRating.tsx.preview | <Typography component="legend">Controlled</Typography>
<Rating
name="simple-controlled"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
/>
<Typography component="legend">Read only</Typography>
<Rating name="read-only" value={value} readOnly />
<Typography component="legend">Disabled</Typography>
<Rating name="disabled" value={value} disabled />
<Typography component="legend">No rating given</Typography>
<Rating name="no-value" value={null} /> | 2,854 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/CustomizedRating.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import FavoriteIcon from '@mui/icons-material/Favorite';
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
import Typography from '@mui/material/Typography';
const StyledRating = styled(Rating)({
'& .MuiRating-iconFilled': {
color: '#ff6d75',
},
'& .MuiRating-iconHover': {
color: '#ff3d47',
},
});
export default function CustomizedRating() {
return (
<Box
sx={{
'& > legend': { mt: 2 },
}}
>
<Typography component="legend">Custom icon and color</Typography>
<StyledRating
name="customized-color"
defaultValue={2}
getLabelText={(value) => `${value} Heart${value !== 1 ? 's' : ''}`}
precision={0.5}
icon={<FavoriteIcon fontSize="inherit" />}
emptyIcon={<FavoriteBorderIcon fontSize="inherit" />}
/>
<Typography component="legend">10 stars</Typography>
<Rating name="customized-10" defaultValue={2} max={10} />
</Box>
);
}
| 2,855 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/CustomizedRating.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import FavoriteIcon from '@mui/icons-material/Favorite';
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
import Typography from '@mui/material/Typography';
const StyledRating = styled(Rating)({
'& .MuiRating-iconFilled': {
color: '#ff6d75',
},
'& .MuiRating-iconHover': {
color: '#ff3d47',
},
});
export default function CustomizedRating() {
return (
<Box
sx={{
'& > legend': { mt: 2 },
}}
>
<Typography component="legend">Custom icon and color</Typography>
<StyledRating
name="customized-color"
defaultValue={2}
getLabelText={(value: number) => `${value} Heart${value !== 1 ? 's' : ''}`}
precision={0.5}
icon={<FavoriteIcon fontSize="inherit" />}
emptyIcon={<FavoriteBorderIcon fontSize="inherit" />}
/>
<Typography component="legend">10 stars</Typography>
<Rating name="customized-10" defaultValue={2} max={10} />
</Box>
);
}
| 2,856 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/CustomizedRating.tsx.preview | <Typography component="legend">Custom icon and color</Typography>
<StyledRating
name="customized-color"
defaultValue={2}
getLabelText={(value: number) => `${value} Heart${value !== 1 ? 's' : ''}`}
precision={0.5}
icon={<FavoriteIcon fontSize="inherit" />}
emptyIcon={<FavoriteBorderIcon fontSize="inherit" />}
/>
<Typography component="legend">10 stars</Typography>
<Rating name="customized-10" defaultValue={2} max={10} /> | 2,857 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/HalfRating.js | import * as React from 'react';
import Rating from '@mui/material/Rating';
import Stack from '@mui/material/Stack';
export default function HalfRating() {
return (
<Stack spacing={1}>
<Rating name="half-rating" defaultValue={2.5} precision={0.5} />
<Rating name="half-rating-read" defaultValue={2.5} precision={0.5} readOnly />
</Stack>
);
}
| 2,858 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/HalfRating.tsx | import * as React from 'react';
import Rating from '@mui/material/Rating';
import Stack from '@mui/material/Stack';
export default function HalfRating() {
return (
<Stack spacing={1}>
<Rating name="half-rating" defaultValue={2.5} precision={0.5} />
<Rating name="half-rating-read" defaultValue={2.5} precision={0.5} readOnly />
</Stack>
);
}
| 2,859 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/HalfRating.tsx.preview | <Rating name="half-rating" defaultValue={2.5} precision={0.5} />
<Rating name="half-rating-read" defaultValue={2.5} precision={0.5} readOnly /> | 2,860 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/HoverRating.js | import * as React from 'react';
import Rating from '@mui/material/Rating';
import Box from '@mui/material/Box';
import StarIcon from '@mui/icons-material/Star';
const labels = {
0.5: 'Useless',
1: 'Useless+',
1.5: 'Poor',
2: 'Poor+',
2.5: 'Ok',
3: 'Ok+',
3.5: 'Good',
4: 'Good+',
4.5: 'Excellent',
5: 'Excellent+',
};
function getLabelText(value) {
return `${value} Star${value !== 1 ? 's' : ''}, ${labels[value]}`;
}
export default function HoverRating() {
const [value, setValue] = React.useState(2);
const [hover, setHover] = React.useState(-1);
return (
<Box
sx={{
width: 200,
display: 'flex',
alignItems: 'center',
}}
>
<Rating
name="hover-feedback"
value={value}
precision={0.5}
getLabelText={getLabelText}
onChange={(event, newValue) => {
setValue(newValue);
}}
onChangeActive={(event, newHover) => {
setHover(newHover);
}}
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
/>
{value !== null && (
<Box sx={{ ml: 2 }}>{labels[hover !== -1 ? hover : value]}</Box>
)}
</Box>
);
}
| 2,861 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/HoverRating.tsx | import * as React from 'react';
import Rating from '@mui/material/Rating';
import Box from '@mui/material/Box';
import StarIcon from '@mui/icons-material/Star';
const labels: { [index: string]: string } = {
0.5: 'Useless',
1: 'Useless+',
1.5: 'Poor',
2: 'Poor+',
2.5: 'Ok',
3: 'Ok+',
3.5: 'Good',
4: 'Good+',
4.5: 'Excellent',
5: 'Excellent+',
};
function getLabelText(value: number) {
return `${value} Star${value !== 1 ? 's' : ''}, ${labels[value]}`;
}
export default function HoverRating() {
const [value, setValue] = React.useState<number | null>(2);
const [hover, setHover] = React.useState(-1);
return (
<Box
sx={{
width: 200,
display: 'flex',
alignItems: 'center',
}}
>
<Rating
name="hover-feedback"
value={value}
precision={0.5}
getLabelText={getLabelText}
onChange={(event, newValue) => {
setValue(newValue);
}}
onChangeActive={(event, newHover) => {
setHover(newHover);
}}
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
/>
{value !== null && (
<Box sx={{ ml: 2 }}>{labels[hover !== -1 ? hover : value]}</Box>
)}
</Box>
);
}
| 2,862 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/HoverRating.tsx.preview | <Rating
name="hover-feedback"
value={value}
precision={0.5}
getLabelText={getLabelText}
onChange={(event, newValue) => {
setValue(newValue);
}}
onChangeActive={(event, newHover) => {
setHover(newHover);
}}
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
/>
{value !== null && (
<Box sx={{ ml: 2 }}>{labels[hover !== -1 ? hover : value]}</Box>
)} | 2,863 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/RadioGroupRating.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import Rating from '@mui/material/Rating';
import SentimentVeryDissatisfiedIcon from '@mui/icons-material/SentimentVeryDissatisfied';
import SentimentDissatisfiedIcon from '@mui/icons-material/SentimentDissatisfied';
import SentimentSatisfiedIcon from '@mui/icons-material/SentimentSatisfied';
import SentimentSatisfiedAltIcon from '@mui/icons-material/SentimentSatisfiedAltOutlined';
import SentimentVerySatisfiedIcon from '@mui/icons-material/SentimentVerySatisfied';
const StyledRating = styled(Rating)(({ theme }) => ({
'& .MuiRating-iconEmpty .MuiSvgIcon-root': {
color: theme.palette.action.disabled,
},
}));
const customIcons = {
1: {
icon: <SentimentVeryDissatisfiedIcon color="error" />,
label: 'Very Dissatisfied',
},
2: {
icon: <SentimentDissatisfiedIcon color="error" />,
label: 'Dissatisfied',
},
3: {
icon: <SentimentSatisfiedIcon color="warning" />,
label: 'Neutral',
},
4: {
icon: <SentimentSatisfiedAltIcon color="success" />,
label: 'Satisfied',
},
5: {
icon: <SentimentVerySatisfiedIcon color="success" />,
label: 'Very Satisfied',
},
};
function IconContainer(props) {
const { value, ...other } = props;
return <span {...other}>{customIcons[value].icon}</span>;
}
IconContainer.propTypes = {
value: PropTypes.number.isRequired,
};
export default function RadioGroupRating() {
return (
<StyledRating
name="highlight-selected-only"
defaultValue={2}
IconContainerComponent={IconContainer}
getLabelText={(value) => customIcons[value].label}
highlightSelectedOnly
/>
);
}
| 2,864 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/RadioGroupRating.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Rating, { IconContainerProps } from '@mui/material/Rating';
import SentimentVeryDissatisfiedIcon from '@mui/icons-material/SentimentVeryDissatisfied';
import SentimentDissatisfiedIcon from '@mui/icons-material/SentimentDissatisfied';
import SentimentSatisfiedIcon from '@mui/icons-material/SentimentSatisfied';
import SentimentSatisfiedAltIcon from '@mui/icons-material/SentimentSatisfiedAltOutlined';
import SentimentVerySatisfiedIcon from '@mui/icons-material/SentimentVerySatisfied';
const StyledRating = styled(Rating)(({ theme }) => ({
'& .MuiRating-iconEmpty .MuiSvgIcon-root': {
color: theme.palette.action.disabled,
},
}));
const customIcons: {
[index: string]: {
icon: React.ReactElement;
label: string;
};
} = {
1: {
icon: <SentimentVeryDissatisfiedIcon color="error" />,
label: 'Very Dissatisfied',
},
2: {
icon: <SentimentDissatisfiedIcon color="error" />,
label: 'Dissatisfied',
},
3: {
icon: <SentimentSatisfiedIcon color="warning" />,
label: 'Neutral',
},
4: {
icon: <SentimentSatisfiedAltIcon color="success" />,
label: 'Satisfied',
},
5: {
icon: <SentimentVerySatisfiedIcon color="success" />,
label: 'Very Satisfied',
},
};
function IconContainer(props: IconContainerProps) {
const { value, ...other } = props;
return <span {...other}>{customIcons[value].icon}</span>;
}
export default function RadioGroupRating() {
return (
<StyledRating
name="highlight-selected-only"
defaultValue={2}
IconContainerComponent={IconContainer}
getLabelText={(value: number) => customIcons[value].label}
highlightSelectedOnly
/>
);
}
| 2,865 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/RadioGroupRating.tsx.preview | <StyledRating
name="highlight-selected-only"
defaultValue={2}
IconContainerComponent={IconContainer}
getLabelText={(value: number) => customIcons[value].label}
highlightSelectedOnly
/> | 2,866 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/RatingSize.js | import * as React from 'react';
import Rating from '@mui/material/Rating';
import Stack from '@mui/material/Stack';
export default function RatingSize() {
return (
<Stack spacing={1}>
<Rating name="size-small" defaultValue={2} size="small" />
<Rating name="size-medium" defaultValue={2} />
<Rating name="size-large" defaultValue={2} size="large" />
</Stack>
);
}
| 2,867 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/RatingSize.tsx | import * as React from 'react';
import Rating from '@mui/material/Rating';
import Stack from '@mui/material/Stack';
export default function RatingSize() {
return (
<Stack spacing={1}>
<Rating name="size-small" defaultValue={2} size="small" />
<Rating name="size-medium" defaultValue={2} />
<Rating name="size-large" defaultValue={2} size="large" />
</Stack>
);
}
| 2,868 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/RatingSize.tsx.preview | <Rating name="size-small" defaultValue={2} size="small" />
<Rating name="size-medium" defaultValue={2} />
<Rating name="size-large" defaultValue={2} size="large" /> | 2,869 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/TextRating.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import StarIcon from '@mui/icons-material/Star';
const labels = {
0.5: 'Useless',
1: 'Useless+',
1.5: 'Poor',
2: 'Poor+',
2.5: 'Ok',
3: 'Ok+',
3.5: 'Good',
4: 'Good+',
4.5: 'Excellent',
5: 'Excellent+',
};
export default function TextRating() {
const value = 3.5;
return (
<Box
sx={{
width: 200,
display: 'flex',
alignItems: 'center',
}}
>
<Rating
name="text-feedback"
value={value}
readOnly
precision={0.5}
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
/>
<Box sx={{ ml: 2 }}>{labels[value]}</Box>
</Box>
);
}
| 2,870 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/TextRating.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import StarIcon from '@mui/icons-material/Star';
const labels: { [index: string]: string } = {
0.5: 'Useless',
1: 'Useless+',
1.5: 'Poor',
2: 'Poor+',
2.5: 'Ok',
3: 'Ok+',
3.5: 'Good',
4: 'Good+',
4.5: 'Excellent',
5: 'Excellent+',
};
export default function TextRating() {
const value = 3.5;
return (
<Box
sx={{
width: 200,
display: 'flex',
alignItems: 'center',
}}
>
<Rating
name="text-feedback"
value={value}
readOnly
precision={0.5}
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
/>
<Box sx={{ ml: 2 }}>{labels[value]}</Box>
</Box>
);
}
| 2,871 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/TextRating.tsx.preview | <Rating
name="text-feedback"
value={value}
readOnly
precision={0.5}
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
/>
<Box sx={{ ml: 2 }}>{labels[value]}</Box> | 2,872 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/rating/rating.md | ---
productId: material-ui
title: React Rating component
components: Rating
githubLabel: 'component: rating'
waiAria: https://www.w3.org/WAI/tutorials/forms/custom-controls/#a-star-rating
---
# Rating
<p class="description">Ratings provide insight regarding others' opinions and experiences, and can allow the user to submit a rating of their own.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Basic rating
{{"demo": "BasicRating.js"}}
## Rating precision
The rating can display any float number with the `value` prop.
Use the `precision` prop to define the minimum increment value change allowed.
{{"demo": "HalfRating.js"}}
## Hover feedback
You can display a label on hover to help the user pick the correct rating value.
The demo uses the `onChangeActive` prop.
{{"demo": "HoverRating.js"}}
## Sizes
For larger or smaller ratings use the `size` prop.
{{"demo": "RatingSize.js"}}
## Customization
Here are some examples of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
{{"demo": "CustomizedRating.js"}}
## Radio group
The rating is implemented with a radio group, set `highlightSelectedOnly` to restore the natural behavior.
{{"demo": "RadioGroupRating.js"}}
## Accessibility
([WAI tutorial](https://www.w3.org/WAI/tutorials/forms/custom-controls/#a-star-rating))
The accessibility of this component relies on:
- A radio group with its fields visually hidden.
It contains six radio buttons, one for each star, and another for 0 stars that is checked by default. Be sure to provide a value for the `name` prop that is unique to the parent form.
- Labels for the radio buttons containing actual text ("1 Star", "2 Stars", …).
Be sure to provide a suitable function to the `getLabelText` prop when the page is in a language other than English. You can use the [included locales](https://mui.com/material-ui/guides/localization/), or provide your own.
- A visually distinct appearance for the rating icons.
By default, the rating component uses both a difference of color and shape (filled and empty icons) to indicate the value. In the event that you are using color as the only means to indicate the value, the information should also be also displayed as text, as in this demo. This is important to match [success Criterion 1.4.1](https://www.w3.org/TR/WCAG21/#use-of-color) of WCAG2.1.
{{"demo": "TextRating.js"}}
### ARIA
The read only rating has a role of "img", and an aria-label that describes the displayed rating.
### Keyboard
Because the rating component uses radio buttons, keyboard interaction follows the native browser behavior. Tab will focus the current rating, and cursor keys control the selected rating.
The read only rating is not focusable.
| 2,873 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/BasicSelect.js | import * as React from 'react';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function BasicSelect() {
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}
>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</Box>
);
}
| 2,874 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/BasicSelect.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
export default function BasicSelect() {
const [age, setAge] = React.useState('');
const handleChange = (event: SelectChangeEvent) => {
setAge(event.target.value as string);
};
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}
>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</Box>
);
}
| 2,875 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/BasicSelect.tsx.preview | <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}
>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl> | 2,876 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/ControlledOpenSelect.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
import Button from '@mui/material/Button';
export default function ControlledOpenSelect() {
const [age, setAge] = React.useState('');
const [open, setOpen] = React.useState(false);
const handleChange = (event) => {
setAge(event.target.value);
};
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
return (
<div>
<Button sx={{ display: 'block', mt: 2 }} onClick={handleOpen}>
Open the select
</Button>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-controlled-open-select-label">Age</InputLabel>
<Select
labelId="demo-controlled-open-select-label"
id="demo-controlled-open-select"
open={open}
onClose={handleClose}
onOpen={handleOpen}
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,877 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/ControlledOpenSelect.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
import Button from '@mui/material/Button';
export default function ControlledOpenSelect() {
const [age, setAge] = React.useState<string | number>('');
const [open, setOpen] = React.useState(false);
const handleChange = (event: SelectChangeEvent<typeof age>) => {
setAge(event.target.value);
};
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
return (
<div>
<Button sx={{ display: 'block', mt: 2 }} onClick={handleOpen}>
Open the select
</Button>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-controlled-open-select-label">Age</InputLabel>
<Select
labelId="demo-controlled-open-select-label"
id="demo-controlled-open-select"
open={open}
onClose={handleClose}
onOpen={handleOpen}
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,878 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/CustomizedSelects.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
import NativeSelect from '@mui/material/NativeSelect';
import InputBase from '@mui/material/InputBase';
const BootstrapInput = styled(InputBase)(({ theme }) => ({
'label + &': {
marginTop: theme.spacing(3),
},
'& .MuiInputBase-input': {
borderRadius: 4,
position: 'relative',
backgroundColor: theme.palette.background.paper,
border: '1px solid #ced4da',
fontSize: 16,
padding: '10px 26px 10px 12px',
transition: theme.transitions.create(['border-color', 'box-shadow']),
// Use the system font instead of the default Roboto font.
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:focus': {
borderRadius: 4,
borderColor: '#80bdff',
boxShadow: '0 0 0 0.2rem rgba(0,123,255,.25)',
},
},
}));
export default function CustomizedSelects() {
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1 }} variant="standard">
<InputLabel htmlFor="demo-customized-textbox">Age</InputLabel>
<BootstrapInput id="demo-customized-textbox" />
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<InputLabel id="demo-customized-select-label">Age</InputLabel>
<Select
labelId="demo-customized-select-label"
id="demo-customized-select"
value={age}
onChange={handleChange}
input={<BootstrapInput />}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<InputLabel htmlFor="demo-customized-select-native">Age</InputLabel>
<NativeSelect
id="demo-customized-select-native"
value={age}
onChange={handleChange}
input={<BootstrapInput />}
>
<option aria-label="None" value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
</FormControl>
</div>
);
}
| 2,879 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/CustomizedSelects.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
import NativeSelect from '@mui/material/NativeSelect';
import InputBase from '@mui/material/InputBase';
const BootstrapInput = styled(InputBase)(({ theme }) => ({
'label + &': {
marginTop: theme.spacing(3),
},
'& .MuiInputBase-input': {
borderRadius: 4,
position: 'relative',
backgroundColor: theme.palette.background.paper,
border: '1px solid #ced4da',
fontSize: 16,
padding: '10px 26px 10px 12px',
transition: theme.transitions.create(['border-color', 'box-shadow']),
// Use the system font instead of the default Roboto font.
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:focus': {
borderRadius: 4,
borderColor: '#80bdff',
boxShadow: '0 0 0 0.2rem rgba(0,123,255,.25)',
},
},
}));
export default function CustomizedSelects() {
const [age, setAge] = React.useState('');
const handleChange = (event: { target: { value: string } }) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1 }} variant="standard">
<InputLabel htmlFor="demo-customized-textbox">Age</InputLabel>
<BootstrapInput id="demo-customized-textbox" />
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<InputLabel id="demo-customized-select-label">Age</InputLabel>
<Select
labelId="demo-customized-select-label"
id="demo-customized-select"
value={age}
onChange={handleChange}
input={<BootstrapInput />}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<InputLabel htmlFor="demo-customized-select-native">Age</InputLabel>
<NativeSelect
id="demo-customized-select-native"
value={age}
onChange={handleChange}
input={<BootstrapInput />}
>
<option aria-label="None" value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
</FormControl>
</div>
);
}
| 2,880 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/DialogSelect.js | 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 [open, setOpen] = React.useState(false);
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(Number(event.target.value) || '');
};
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = (event, reason) => {
if (reason !== 'backdropClick') {
setOpen(false);
}
};
return (
<div>
<Button onClick={handleClickOpen}>Open select dialog</Button>
<Dialog disableEscapeKeyDown open={open} onClose={handleClose}>
<DialogTitle>Fill the form</DialogTitle>
<DialogContent>
<Box component="form" sx={{ display: 'flex', flexWrap: 'wrap' }}>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="demo-dialog-native">Age</InputLabel>
<Select
native
value={age}
onChange={handleChange}
input={<OutlinedInput label="Age" id="demo-dialog-native" />}
>
<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="demo-dialog-select-label">Age</InputLabel>
<Select
labelId="demo-dialog-select-label"
id="demo-dialog-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={handleClose}>Cancel</Button>
<Button onClick={handleClose}>Ok</Button>
</DialogActions>
</Dialog>
</div>
);
}
| 2,881 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/DialogSelect.tsx | 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, { SelectChangeEvent } from '@mui/material/Select';
export default function DialogSelect() {
const [open, setOpen] = React.useState(false);
const [age, setAge] = React.useState<number | string>('');
const handleChange = (event: SelectChangeEvent<typeof age>) => {
setAge(Number(event.target.value) || '');
};
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = (event: React.SyntheticEvent<unknown>, reason?: string) => {
if (reason !== 'backdropClick') {
setOpen(false);
}
};
return (
<div>
<Button onClick={handleClickOpen}>Open select dialog</Button>
<Dialog disableEscapeKeyDown open={open} onClose={handleClose}>
<DialogTitle>Fill the form</DialogTitle>
<DialogContent>
<Box component="form" sx={{ display: 'flex', flexWrap: 'wrap' }}>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="demo-dialog-native">Age</InputLabel>
<Select
native
value={age}
onChange={handleChange}
input={<OutlinedInput label="Age" id="demo-dialog-native" />}
>
<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="demo-dialog-select-label">Age</InputLabel>
<Select
labelId="demo-dialog-select-label"
id="demo-dialog-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={handleClose}>Cancel</Button>
<Button onClick={handleClose}>Ok</Button>
</DialogActions>
</Dialog>
</div>
);
}
| 2,882 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/GroupedSelect.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import ListSubheader from '@mui/material/ListSubheader';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function GroupedSelect() {
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-native-select">Grouping</InputLabel>
<Select native defaultValue="" id="grouped-native-select" label="Grouping">
<option aria-label="None" value="" />
<optgroup label="Category 1">
<option value={1}>Option 1</option>
<option value={2}>Option 2</option>
</optgroup>
<optgroup label="Category 2">
<option value={3}>Option 3</option>
<option value={4}>Option 4</option>
</optgroup>
</Select>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-select">Grouping</InputLabel>
<Select defaultValue="" id="grouped-select" label="Grouping">
<MenuItem value="">
<em>None</em>
</MenuItem>
<ListSubheader>Category 1</ListSubheader>
<MenuItem value={1}>Option 1</MenuItem>
<MenuItem value={2}>Option 2</MenuItem>
<ListSubheader>Category 2</ListSubheader>
<MenuItem value={3}>Option 3</MenuItem>
<MenuItem value={4}>Option 4</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,883 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/GroupedSelect.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import ListSubheader from '@mui/material/ListSubheader';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function GroupedSelect() {
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-native-select">Grouping</InputLabel>
<Select native defaultValue="" id="grouped-native-select" label="Grouping">
<option aria-label="None" value="" />
<optgroup label="Category 1">
<option value={1}>Option 1</option>
<option value={2}>Option 2</option>
</optgroup>
<optgroup label="Category 2">
<option value={3}>Option 3</option>
<option value={4}>Option 4</option>
</optgroup>
</Select>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-select">Grouping</InputLabel>
<Select defaultValue="" id="grouped-select" label="Grouping">
<MenuItem value="">
<em>None</em>
</MenuItem>
<ListSubheader>Category 1</ListSubheader>
<MenuItem value={1}>Option 1</MenuItem>
<MenuItem value={2}>Option 2</MenuItem>
<ListSubheader>Category 2</ListSubheader>
<MenuItem value={3}>Option 3</MenuItem>
<MenuItem value={4}>Option 4</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,884 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelect.js | import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
function getStyles(name, personName, theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
export default function MultipleSelect() {
const theme = useTheme();
const [personName, setPersonName] = React.useState([]);
const handleChange = (event) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="demo-multiple-name-label">Name</InputLabel>
<Select
labelId="demo-multiple-name-label"
id="demo-multiple-name"
multiple
value={personName}
onChange={handleChange}
input={<OutlinedInput label="Name" />}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,885 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelect.tsx | import * as React from 'react';
import { Theme, useTheme } from '@mui/material/styles';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
function getStyles(name: string, personName: string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
export default function MultipleSelect() {
const theme = useTheme();
const [personName, setPersonName] = React.useState<string[]>([]);
const handleChange = (event: SelectChangeEvent<typeof personName>) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="demo-multiple-name-label">Name</InputLabel>
<Select
labelId="demo-multiple-name-label"
id="demo-multiple-name"
multiple
value={personName}
onChange={handleChange}
input={<OutlinedInput label="Name" />}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,886 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectCheckmarks.js | import * as React from 'react';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import ListItemText from '@mui/material/ListItemText';
import Select from '@mui/material/Select';
import Checkbox from '@mui/material/Checkbox';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
export default function MultipleSelectCheckmarks() {
const [personName, setPersonName] = React.useState([]);
const handleChange = (event) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="demo-multiple-checkbox-label">Tag</InputLabel>
<Select
labelId="demo-multiple-checkbox-label"
id="demo-multiple-checkbox"
multiple
value={personName}
onChange={handleChange}
input={<OutlinedInput label="Tag" />}
renderValue={(selected) => selected.join(', ')}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem key={name} value={name}>
<Checkbox checked={personName.indexOf(name) > -1} />
<ListItemText primary={name} />
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,887 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectCheckmarks.tsx | import * as React from 'react';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import ListItemText from '@mui/material/ListItemText';
import Select, { SelectChangeEvent } from '@mui/material/Select';
import Checkbox from '@mui/material/Checkbox';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
export default function MultipleSelectCheckmarks() {
const [personName, setPersonName] = React.useState<string[]>([]);
const handleChange = (event: SelectChangeEvent<typeof personName>) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="demo-multiple-checkbox-label">Tag</InputLabel>
<Select
labelId="demo-multiple-checkbox-label"
id="demo-multiple-checkbox"
multiple
value={personName}
onChange={handleChange}
input={<OutlinedInput label="Tag" />}
renderValue={(selected) => selected.join(', ')}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem key={name} value={name}>
<Checkbox checked={personName.indexOf(name) > -1} />
<ListItemText primary={name} />
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,888 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectChip.js | import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
import Chip from '@mui/material/Chip';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
function getStyles(name, personName, theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
export default function MultipleSelectChip() {
const theme = useTheme();
const [personName, setPersonName] = React.useState([]);
const handleChange = (event) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="demo-multiple-chip-label">Chip</InputLabel>
<Select
labelId="demo-multiple-chip-label"
id="demo-multiple-chip"
multiple
value={personName}
onChange={handleChange}
input={<OutlinedInput id="select-multiple-chip" label="Chip" />}
renderValue={(selected) => (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
{selected.map((value) => (
<Chip key={value} label={value} />
))}
</Box>
)}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,889 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectChip.tsx | import * as React from 'react';
import { Theme, useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
import Chip from '@mui/material/Chip';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
function getStyles(name: string, personName: readonly string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
export default function MultipleSelectChip() {
const theme = useTheme();
const [personName, setPersonName] = React.useState<string[]>([]);
const handleChange = (event: SelectChangeEvent<typeof personName>) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id="demo-multiple-chip-label">Chip</InputLabel>
<Select
labelId="demo-multiple-chip-label"
id="demo-multiple-chip"
multiple
value={personName}
onChange={handleChange}
input={<OutlinedInput id="select-multiple-chip" label="Chip" />}
renderValue={(selected) => (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
{selected.map((value) => (
<Chip key={value} label={value} />
))}
</Box>
)}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,890 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectNative.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
export default function MultipleSelectNative() {
const [personName, setPersonName] = React.useState([]);
const handleChangeMultiple = (event) => {
const { options } = event.target;
const value = [];
for (let i = 0, l = options.length; i < l; i += 1) {
if (options[i].selected) {
value.push(options[i].value);
}
}
setPersonName(value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120, maxWidth: 300 }}>
<InputLabel shrink htmlFor="select-multiple-native">
Native
</InputLabel>
<Select
multiple
native
value={personName}
onChange={handleChangeMultiple}
label="Native"
inputProps={{
id: 'select-multiple-native',
}}
>
{names.map((name) => (
<option key={name} value={name}>
{name}
</option>
))}
</Select>
</FormControl>
</div>
);
}
| 2,891 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectNative.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
export default function MultipleSelectNative() {
const [personName, setPersonName] = React.useState<string[]>([]);
const handleChangeMultiple = (event: React.ChangeEvent<HTMLSelectElement>) => {
const { options } = event.target;
const value: string[] = [];
for (let i = 0, l = options.length; i < l; i += 1) {
if (options[i].selected) {
value.push(options[i].value);
}
}
setPersonName(value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120, maxWidth: 300 }}>
<InputLabel shrink htmlFor="select-multiple-native">
Native
</InputLabel>
<Select
multiple
native
value={personName}
// @ts-ignore Typings are not considering `native`
onChange={handleChangeMultiple}
label="Native"
inputProps={{
id: 'select-multiple-native',
}}
>
{names.map((name) => (
<option key={name} value={name}>
{name}
</option>
))}
</Select>
</FormControl>
</div>
);
}
| 2,892 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectPlaceholder.js | import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import OutlinedInput from '@mui/material/OutlinedInput';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
function getStyles(name, personName, theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
export default function MultipleSelectPlaceholder() {
const theme = useTheme();
const [personName, setPersonName] = React.useState([]);
const handleChange = (event) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300, mt: 3 }}>
<Select
multiple
displayEmpty
value={personName}
onChange={handleChange}
input={<OutlinedInput />}
renderValue={(selected) => {
if (selected.length === 0) {
return <em>Placeholder</em>;
}
return selected.join(', ');
}}
MenuProps={MenuProps}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem disabled value="">
<em>Placeholder</em>
</MenuItem>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,893 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/MultipleSelectPlaceholder.tsx | import * as React from 'react';
import { Theme, useTheme } from '@mui/material/styles';
import OutlinedInput from '@mui/material/OutlinedInput';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];
function getStyles(name: string, personName: readonly string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
export default function MultipleSelectPlaceholder() {
const theme = useTheme();
const [personName, setPersonName] = React.useState<string[]>([]);
const handleChange = (event: SelectChangeEvent<typeof personName>) => {
const {
target: { value },
} = event;
setPersonName(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
return (
<div>
<FormControl sx={{ m: 1, width: 300, mt: 3 }}>
<Select
multiple
displayEmpty
value={personName}
onChange={handleChange}
input={<OutlinedInput />}
renderValue={(selected) => {
if (selected.length === 0) {
return <em>Placeholder</em>;
}
return selected.join(', ');
}}
MenuProps={MenuProps}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem disabled value="">
<em>Placeholder</em>
</MenuItem>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
| 2,894 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/NativeSelectDemo.js | import * as React from 'react';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import FormControl from '@mui/material/FormControl';
import NativeSelect from '@mui/material/NativeSelect';
export default function NativeSelectDemo() {
return (
<Box sx={{ minWidth: 120 }}>
<FormControl fullWidth>
<InputLabel variant="standard" htmlFor="uncontrolled-native">
Age
</InputLabel>
<NativeSelect
defaultValue={30}
inputProps={{
name: 'age',
id: 'uncontrolled-native',
}}
>
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
</FormControl>
</Box>
);
}
| 2,895 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/NativeSelectDemo.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import FormControl from '@mui/material/FormControl';
import NativeSelect from '@mui/material/NativeSelect';
export default function NativeSelectDemo() {
return (
<Box sx={{ minWidth: 120 }}>
<FormControl fullWidth>
<InputLabel variant="standard" htmlFor="uncontrolled-native">
Age
</InputLabel>
<NativeSelect
defaultValue={30}
inputProps={{
name: 'age',
id: 'uncontrolled-native',
}}
>
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
</FormControl>
</Box>
);
}
| 2,896 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/NativeSelectDemo.tsx.preview | <FormControl fullWidth>
<InputLabel variant="standard" htmlFor="uncontrolled-native">
Age
</InputLabel>
<NativeSelect
defaultValue={30}
inputProps={{
name: 'age',
id: 'uncontrolled-native',
}}
>
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
</FormControl> | 2,897 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectAutoWidth.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function SelectAutoWidth() {
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 80 }}>
<InputLabel id="demo-simple-select-autowidth-label">Age</InputLabel>
<Select
labelId="demo-simple-select-autowidth-label"
id="demo-simple-select-autowidth"
value={age}
onChange={handleChange}
autoWidth
label="Age"
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Twenty</MenuItem>
<MenuItem value={21}>Twenty one</MenuItem>
<MenuItem value={22}>Twenty one and a half</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,898 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectAutoWidth.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
export default function SelectAutoWidth() {
const [age, setAge] = React.useState('');
const handleChange = (event: SelectChangeEvent) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 80 }}>
<InputLabel id="demo-simple-select-autowidth-label">Age</InputLabel>
<Select
labelId="demo-simple-select-autowidth-label"
id="demo-simple-select-autowidth"
value={age}
onChange={handleChange}
autoWidth
label="Age"
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Twenty</MenuItem>
<MenuItem value={21}>Twenty one</MenuItem>
<MenuItem value={22}>Twenty one and a half</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,899 |
Subsets and Splits