New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[material-ui][Select] displayEmpty=true
renders label over value
#42148
Comments
displayEmpty=true
renders label over value
Hey @rgavrilov i have two suggestions you can try: 1)You can provide a default non-empty value for the Select component. |
@rgavrilov When you use You should also use <FormControl>
<InputLabel shrink={val || val === ''}>
Calculator
</InputLabel>
<Select
value={val}
label="Calculator"
onChange={(e) => setVal(e.target.value)}
displayEmpty
renderValue={(val) => {
if (val === '') {
return 'All options';
}
return val;
}}
>
<MenuItem value="">
All
</MenuItem>
<MenuItem value="B">
B
</MenuItem>
<MenuItem value="C">
C
</MenuItem>
</Select>
</FormControl> Here's a working demo: https://stackblitz.com/edit/mcve-react-material-ui-rx1lgs?file=src%2FApp.tsx |
👋 Thanks for using our open-source projects! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support with Material UI please check out https://mui.com/material-ui/getting-started/support/. Thanks! If you have a question on Stack Overflow, you are welcome to link to it here, it might help others. |
The problem in depth
When MenuItem value is empty string, see code below, form control label is rendered over the selected item content.
Your environment
`npx @mui/envinfo`
Search keywords: Select displayEmpty
Order ID: 52426
Search keywords:
The text was updated successfully, but these errors were encountered: