Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/data/material/components/selects/SelectLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function SelectLabels() {
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-helper-label">Age</InputLabel>
<Select
aria-describedby="demo-simple-select-helper-text"
labelId="demo-simple-select-helper-label"
id="demo-simple-select-helper"
value={age}
Expand All @@ -30,14 +31,17 @@ export default function SelectLabels() {
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>With label + helper text</FormHelperText>
<FormHelperText id="demo-simple-select-helper-text">
Visible label and helper text
</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<Select
aria-describedby="demo-no-label-select-helper-text"
value={age}
onChange={handleChange}
displayEmpty
inputProps={{ 'aria-label': 'Without label' }}
inputProps={{ 'aria-label': 'Age' }}
>
<MenuItem value="">
<em>None</em>
Expand All @@ -46,7 +50,9 @@ export default function SelectLabels() {
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Without label</FormHelperText>
<FormHelperText id="demo-no-label-select-helper-text">
aria-label and helper text
</FormHelperText>
</FormControl>
</div>
);
Expand Down
12 changes: 9 additions & 3 deletions docs/data/material/components/selects/SelectLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function SelectLabels() {
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-helper-label">Age</InputLabel>
<Select
aria-describedby="demo-simple-select-helper-text"
labelId="demo-simple-select-helper-label"
id="demo-simple-select-helper"
value={age}
Expand All @@ -30,14 +31,17 @@ export default function SelectLabels() {
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>With label + helper text</FormHelperText>
<FormHelperText id="demo-simple-select-helper-text">
Visible label and helper text
</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<Select
aria-describedby="demo-no-label-select-helper-text"
value={age}
onChange={handleChange}
displayEmpty
inputProps={{ 'aria-label': 'Without label' }}
inputProps={{ 'aria-label': 'Age' }}
>
<MenuItem value="">
<em>None</em>
Expand All @@ -46,7 +50,9 @@ export default function SelectLabels() {
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Without label</FormHelperText>
<FormHelperText id="demo-no-label-select-helper-text">
aria-label and helper text
</FormHelperText>
</FormControl>
</div>
);
Expand Down
18 changes: 17 additions & 1 deletion docs/data/material/components/selects/SelectVariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@ export default function SelectVariants() {

return (
<div>
<FormControl variant="outlined" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-outlined-label">Age</InputLabel>
<Select
labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined"
value={age}
onChange={handleChange}
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>
<FormControl variant="standard" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-standard-label">Age</InputLabel>
<Select
labelId="demo-simple-select-standard-label"
id="demo-simple-select-standard"
value={age}
onChange={handleChange}
label="Age"
>
<MenuItem value="">
<em>None</em>
Expand Down
18 changes: 17 additions & 1 deletion docs/data/material/components/selects/SelectVariants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@ export default function SelectVariants() {

return (
<div>
<FormControl variant="outlined" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-outlined-label">Age</InputLabel>
<Select
labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined"
value={age}
onChange={handleChange}
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>
<FormControl variant="standard" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-standard-label">Age</InputLabel>
<Select
labelId="demo-simple-select-standard-label"
id="demo-simple-select-standard"
value={age}
onChange={handleChange}
label="Age"
>
<MenuItem value="">
<em>None</em>
Expand Down
12 changes: 7 additions & 5 deletions docs/data/material/components/selects/selects.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ It shares the same styles and many of the same props. Refer to the respective co
Unlike input components, the `placeholder` prop is not available in Select. To add a placeholder, refer to the [placeholder](#placeholder) section below.
:::

### Filled and standard variants
### Variants

{{"demo": "SelectVariants.js"}}

:::warning
Note that when using FormControl with the outlined variant of the Select, you need to provide a label in two places: in the InputLabel component and in the `label` prop of the Select component (see the above demo). This is needed for the label floating animation to work correctly.
:::

### Labels and helper text

{{"demo": "SelectLabels.js"}}
Select always needs an accessible name. This can come from an associated visible label, such as an `InputLabel` linked to the `Select` with `labelId` or from adding an `aria-label` prop to the input element props (`inputProps`). If more information is needed, provide a helper text element and link it to the `Select` using `aria-describedby`.

:::warning
Note that when using FormControl with the outlined variant of the Select, you need to provide a label in two places: in the InputLabel component and in the `label` prop of the Select component (see the above demo).
:::
{{"demo": "SelectLabels.js"}}

### Auto width

Expand Down
Loading