question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Select use same height/lineHeight/vertical padding as Input to fix bad alignment

See original GitHub issue

When I customized the fontSize of my Inputs, side-by-side Select and TextField components became vertically misaligned by one pixel: image

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.

image image

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:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
petrdsvobodacommented, Jul 11, 2018

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) image

Firefox image

CodeSandbox

0reactions
iamoliviniuscommented, Jun 21, 2018

Just updated to FF 60.0.2. Still an issue

screenshot-2018-6-21 codesandbox

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found