Skip to content

fix(material/form-field): center outlined label irrespective of outline width and font size - #33681

Open
jjalbuenacabuyao wants to merge 1 commit into
angular:mainfrom
jjalbuenacabuyao:label-position-outline-width
Open

fix(material/form-field): center outlined label irrespective of outline width and font size#33681
jjalbuenacabuyao wants to merge 1 commit into
angular:mainfrom
jjalbuenacabuyao:label-position-outline-width

Conversation

@jjalbuenacabuyao

Copy link
Copy Markdown

The floating label of the outline appearance is positioned relatively inside the notch, which means that its offset is added on top of the notch's content box. That box is inset by the outline's top border, so the label ended up outline-width below the center of the form field. This is most noticeable when the outline width is animated, e.g. from 1px to 2px on hover, because the label jumps as the outline grows.

The label is also an inline block which makes it align against the notch's baseline. Any difference between the label's font metrics and the inherited line height pushed the label further down, which translateY(-50%) cannot account for since it only knows about the label's own height.

Expose the current outline width through a variable and offset the resting label by it, and align the label with the top of the notch's content box so that it no longer depends on the surrounding line height. Note that the offset only applies while the label is resting, because the notch drops its top border while it is notched.

Fixes #31474

…ne width and font size

The floating label of the outline appearance is positioned relatively inside the
notch, which means that its offset is added on top of the notch's content box.
That box is inset by the outline's top border, so the label ended up
`outline-width` below the center of the form field. This is most noticeable when
the outline width is animated, e.g. from 1px to 2px on hover, because the label
jumps as the outline grows.

The label is also an inline block which makes it align against the notch's
baseline. Any difference between the label's font metrics and the inherited line
height pushed the label further down, which `translateY(-50%)` cannot account for
since it only knows about the label's own height.

Expose the current outline width through a variable and offset the resting label
by it, and align the label with the top of the notch's content box so that it no
longer depends on the surrounding line height. Note that the offset only applies
while the label is resting, because the notch drops its top border while it is
notched.

Fixes angular#31474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(form-field): label position doesn't take outline-width into consideration

1 participant