[Select] Make width of select box as long as label.
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Select boxes have the same width as the label for the specific select box.
Current Behavior
Select box always has a width of 38px, no matter which label.
Context
I created a select box like this
const formControlOptions = {
disabled: requirementFilter.values.length <= 1,
};
<FormControl {...formControlOptions}>
<InputLabel htmlFor={requirementFilter.id}>
{requirementFilter.label}
</InputLabel>
<Select key={requirementFilter.id}
value={this.state.selectedFilters[requirementFilter.id] || ""}
inputProps={{
name: requirementFilter.id,
id: requirementFilter.id,
}}
onChange={this.handleRequirementFilterSelected}
children={requirementFilter.values.map((value: RequirementFilterValue) => {
return (
<MenuItem value={value.id} data-parent={value.parent}>
{value.label} ({value.item_count})
</MenuItem>
);
})}/>
</FormControl>
This creates a selectbox, that looks like this
However, I want it to look like this
I could set the min-width, however, I want all select boxes to have a dynamic width, because some labels are shorter, therefore I also want a lower min-width for other select boxes, so min-width is not a possible solution.
Your Environment
Tech | Version |
---|---|
Material-UI | v1.0.0-beta.39 |
React | 16 |
browser | Chrome (latest) |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to control the width of select tag? - html
You need to use max-width instead. This way, it will let the select menu expand to its longest option, but if that expands...
Read more >[Select] Make width of select box as long as label. #10917
Select box always has a width of 38px, no matter which label. Context. I created a select box like this. const formControlOptions =...
Read more >How to Expand Select Box to its Default Width on Focus ...
Answer: Use the CSS :focus pseudo-class. By default the size of the <select> element is depend on the size of the largest <option>...
Read more >Controlling the width of SELECT lists
The default width of a SELECT form control is usually dependent on the width of the widest OPTION item in the list; the...
Read more >How To Set Width Of Select Option In HTML
In this tutorial we will show the solution of how to set width of select option in HTML, in HTML there is a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, thanks to you pointing out that the label is the problem, I tried to do this
This leads to the expected result. Since I’m no CSS expert, do you see any major problems with that solution? It’s resolution independent because we display this site only to users with a specific resolution.
Ah, I think there was a misunderstanding. I was just pointing out how I solved this, not how the library should solve this! So, this wasn’t a suggestion, but merely a description how I implemented it in case someone else stumbles upon this issue.
Thanks for your help!