Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(MatFormFieldModule): Label is outside the bounds of the form field #27431

Open
GeorgianStan opened this issue Jul 11, 2023 · 1 comment
Open
Assignees
Labels
area: material/form-field P4 A relatively minor issue that is not relevant to core functions

Comments

@GeorgianStan
Copy link
Contributor

GeorgianStan commented Jul 11, 2023

The label associated with a MatFormField is not positioned correctly.

Case 1 - matPrefix
As visible in the following image, the label is outside the bounds of the form field.

1

Inside form-field.ts - _updateOutlineLabelOffset() the HTML element is moved on the x-axis:

floatingLabel.style.transform = `var( --mat-mdc-form-field-label-transform, {FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM} translateX(${labelHorizontalOffset}))`;

This is also visible in DevTools.
This transformation rule looks valid because it has a prefix icon.
But in addition, if the element is moved on the x-axis, its width should be reduced by a value equal to the offset to fit the form field bounds.

width: calc(100% - calc(1 * (51.97072219848633px + var(--mat-mdc-form-field-label-offset-x, 0px))));

2

Case 2 - matSuffix
For matSuffix the fix would be easier, it should only update its width with the offset value.

4

However here it seems that the offset variable is missing from the scss file.
var

Adding the CSS variable to the above file and updating the width should help with this issue.

Reproduction

StackBlitz link: https://stackblitz.com/edit/rudguk-yo1ggv?file=src%2Fexample%2Fform-field-appearance-example.html

Expected Behavior

I expect the label to fit into the borders of the wrapping element.

Actual Behavior

The label goes outside the borders of the wrapping element.

Environment

  • Angular: latest
  • CDK/Material: latest
  • Browser(s): Any
  • Operating System (e.g. Windows, macOS, Ubuntu): Any
@GeorgianStan GeorgianStan added the needs triage This issue needs to be triaged by the team label Jul 11, 2023
@zarend
Copy link
Contributor

zarend commented Jul 11, 2023

Hello,

Thank you for reporting this and proving stackblitz example. Assigning to @mmalerba , who is owner of form-field.

IF you're looking to contribute, feel free to send us a PR that fixes this.

-Zach

@zarend zarend added P4 A relatively minor issue that is not relevant to core functions area: material/form-field and removed needs triage This issue needs to be triaged by the team labels Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/form-field P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

3 participants