mui / mui/material-ui

[text field] Outlined input label is one pixel off

Open
#44,341 4 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

design has workaround scope: text field type: enhancement
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Steps to reproduce

Here are 4 focused inputs:

image

  1. Outlined input as seen on https://mui.com/material-ui/react-text-field/

This input's styles have

transform: translate(14px, -9px) scale(0.75);

by default.

  1. Same input, but I've set
transform: translate(15px, -9px) scale(0.75);

Just comparing input 1 and input 2, to my eye, the "margin" where there is no border looks more even in the version 2 than in the version 1. But, we can check that if we see where the "margin" comes from

  1. Input 1, but with fieldset set to visibility: visible and label inside to opacity: 1, the white text is the aria label that also serves, thanks to it's padding, to create this "magin" in the border.

  2. Input 2, but with fieldset visible.

It is quite clear in inputs 3 and 4 that the label is misaligned to the fieldset. The version in 4th is still not quite 100% there, but it's much less than a pixel off, so I'm not sure what can be done about it.

In order to fix the mismatch either the fieldset invisible version must be moved, or the visible version must be moved.

If the transtion is to be changed, here it is:
(but don't forget about the non-focused versions)

https://github.com/mui/material-ui/blob/412dcbf9d54b29d85353f1ff9947a78beb6ed7c1/packages/mui-material/src/InputLabel/InputLabel.js#L169

Another option is to change the NotchedOutline here:

https://github.com/mui/material-ui/blob/412dcbf9d54b29d85353f1ff9947a78beb6ed7c1/packages/mui-material/src/OutlinedInput/NotchedOutline.js#L16

from padding: 0 8px to padding: 0 7px, because 1px of horizontal size is provided by the border anyway. I think this is actually the most correct change.

Search keywords: Outlined input label misaligned

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.