fix(material/form-field): center outlined label irrespective of outline width and font size - #33681
Open
jjalbuenacabuyao wants to merge 1 commit into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-widthbelow 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