Make Select use same height/lineHeight/vertical padding as Input to fix bad alignment
See original GitHub issueWhen I customized the fontSize
of my Input
s, side-by-side Select
and TextField
components became vertically misaligned by one pixel:
The JSS for Select
overrides the height
, lineHeight
, paddingTop
, and paddingBottom
of the input-singleLine
class, wrecking the vertical alignment. It seems to me all of the vertical sizing properties should match.
I will create a PR in a moment.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Select
has same height
, lineHeight
, and vertical padding
as Input
by default.
Current Behavior
Steps to Reproduce (for bugs)
Customize Input
fontSize
:
theme.overrides = {
MuiInput: {
root: {
fontSize: theme.typography.pxToRem(20),
},
},
}
Render a Select
and a TextField
side-by-side:
<table>
<tbody>
<tr>
<td>
<Select value="default">
<MenuItem value="default">Select</MenuItem>
<Select>
</td>
<td>
<TextField placeholder="TextField" />
</td>
<tr>
</tbody>
</table>
Workaround
Use the following theme override:
MuiSelect: {
// see https://github.com/mui-org/material-ui/issues/9826
select: {
padding: undefined,
paddingRight: theme.spacing.unit * 4,
height: undefined,
},
selectMenu: {
lineHeight: undefined,
},
},
Context
Your Environment
Tech | Version |
---|---|
Material-UI | 1.0.0-beta.25 |
React | 16.2.0 |
browser | Chrome 63.0.3239.132 |
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Vertically align text within input field of fixed-height without ...
I ran into this problem myself. I found that not specifying an input height, but using the font-height and padding combined, results in...
Read more >Problem positioning Select Box - HTML & CSS - SitePoint
Hello. I have a simple address form that was working well until I decided to change the State field from an input box...
Read more >Fixing spacing issues and using helper classes - Pega Academy
Spacing and alignment issues are common errors when building UI screens. It is important to address these issues because they can create an...
Read more >Select next to input field in one row not aligned - MDBootstrap
Hi, when I try to put a input field next to a select it just doesn't look good. The select is not aligned...
Read more >Help please! why is the select input not aligned with the Name ...
hmm in my case, all of my other labels in the form is in one single fieldset, so using the selector fieldset label...
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
I have this issue too, but with Simple Select. I haven’t tried Native Select.
I have tried this on Chrome 67, Firefox 61 and in Code Sandbox. I managed to encounter different amounts of misalignment.
Setting margin to FormControl helps, but it doesn’t work on Firefox and there’s still 1px gap on Chrome. Also setting value to the fields helps sometimes.
Chrome (not perfectly aligned)
Firefox
CodeSandbox
Just updated to FF 60.0.2. Still an issue