[Select] autoWidth=true does not adjust width to the largest option
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
<TextField
select
SelectProps={{ autoWidth: true }}
>
<MenuItem value=""><em>None</em></MenuItem>
<MenuItem value={10}>Short</MenuItem>
<MenuItem value={20}>A bit longer</MenuItem>
<MenuItem value={30}>Very, very, very long</MenuItem>
</TextField>
Should display a long textField, as long as the "Very, very, very long" option.
Current Behavior

The TextField is very short, it uses the width of the selected option. When nothing is selected, it is just not usable.
Besides, having the width of the field change according to the selected element is disturbing.
Steps to Reproduce (for bugs)
https://codesandbox.io/s/mj7zw8plx8
Context
I'm trying to migrate admin-on-rest to material-ui 1.0
Your Environment
| Tech | Version |
|---|---|
| Material-UI | 1.0.0-beta.17 |
| React | 15.6 |
| browser | Chrome |
| etc |
The autoWidth feature was discussed in this issue #8286. It's disabled by default. It's not about making the input following the menu width. It's the other way around. This property is about how is the input width impacts the menu width. For your use case, you ganna have to set a width (or min-width) to the input. It's something we do in the demo. I would have loved to fix your codesandbox, but for some reason, your example doesn't compile.
My bad, the documentation was clear about it.
But then I have another grief: why doesn't the <TextField select> have a reasonable default width? It used to be in 0.x.
@fzaninotto As far as I know, we don't set any width by default to the input. It's behaving like a native input. Well, it's a good question. I haven't though about it. So far the logic is to be as close as possible to the native implementation.
How do you set 100% width on the select so that it fits the width of container ?
@shamseerahammedm Add style to formControl like this
const useStyles = makeStyles((theme) => ({
formControl: {
margin: theme.spacing(1),
minWidth: 'calc(100%)',
maxWidth: 300,
}
}));
@abitgen there is fullWidth prop in FormControl API:
<FormControl fullWidth>
@fzaninotto How did you fix the issue?
@shamseerahammedm Add style to formControl like this
const useStyles = makeStyles((theme) => ({ formControl: { margin: theme.spacing(1), minWidth: 'calc(100%)', maxWidth: 300, } }));
This didn't work for me, but I managed to make the select component fit the list size like this:
<FormControl sx={{
minWidth: 340,
maxWidth: '100%',
}}>
<Select ...>
</FormControl>
Hope this help.
How Can I align the width?