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

Mat-form-field outline rendered incorrectly when direction='rtl' #18857

Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@mihaionduma
Copy link

What's the bug:

When changing the direction of a matFormField, the outline gap doesn't render correctly.

Steps to reproduce:

  1. Build a form with a mat-form-field in it
  2. Add a mat-label tag with a string inside it
  3. add a span tag with a prefix attribute
  4. Change the direction of the mat-form-field to rtl

or

See https://stackblitz.com/edit/angular-vwwrbm-8xrx3b

Expected Behavior

I was expecting the outline and its label to be rendered correctly, even with the prefix and suffix labels inside the mat-form-field.

Actual Behavior

When changing the direction of a mat-form-field, the outline gap doesn't render correctly, there's a gap where the mat-label should be. Also this is affected by having a prefix inside the mat-form-field, somehow the prefix's width decrements the outline label left positioning instead of increasing it.

Also the outline itself of the mat-form-file is not rendered correctly.

Also the MatFormField updateOutlineGap() doesn't update the material correctly, when the direction is rtl. I'm calling updateOutlineGap everytime the direction changes, ltr works ok but rtl is out of place.

Environment

  • Angular: 9.0.0
  • CDK/Material: 9.1.3
  • Browser(s): Chrome 80.0.3987.132
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
@mihaionduma mihaionduma added the needs triage This issue needs to be triaged by the team label Mar 18, 2020
@crisbeto
Copy link
Member

In general Material components don't respond to the CSS direction property, because there's no way for us to detect it. You should use the dir HTML attribute instead.

@mihaionduma
Copy link
Author

In general Material components don't respond to the CSS direction property, because there's no way for us to detect it. You should use the dir HTML attribute instead.

Thank you for your speedy reply.
I've modified the stackblitz to have dir in its html attribute, the bug is still there.

https://stackblitz.com/edit/angular-vwwrbm-8xrx3b

@crisbeto
Copy link
Member

The example you linked is the same as the original one, but here's something that works: https://stackblitz.com/edit/angular-vwwrbm-dtrw7y

@mihaionduma
Copy link
Author

mihaionduma commented Mar 19, 2020

I've managed to reproduce the problem in your example. The problem is that if the [dir] receives only a string and not a expression the initial outline is not rendered correctly.

https://stackblitz.com/edit/angular-vwwrbm-srpxkk

LATER EDIT: The bug also reproduces if you choose to start with rtl in the [dir] expression tag, like so: https://stackblitz.com/edit/angular-vwwrbm-ez6q1q

crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 19, 2020
…ence of a prefix

The logic that figures out the outline gap in the presence of a prefix was producing a negative width which is invalid. It seems like this has been there since the beginning, but we haven't noticed it, because our dev app doesn't have many examples with a prefix and it always starts off from LTR and we switch it to RTL manually which doesn't have this problem since it already got a valid width while it was in LTR.

Fixes angular#18857.
@crisbeto
Copy link
Member

Thank you, now I see it. We have an incorrect calculation that I've fixed in #18867.

@crisbeto crisbeto added has pr P2 The issue is important to a large percentage of users, with a workaround and removed needs triage This issue needs to be triaged by the team labels Mar 19, 2020
@crisbeto crisbeto self-assigned this Mar 19, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 20, 2020
…ence of a prefix

The logic that figures out the outline gap in the presence of a prefix was producing a negative width which is invalid. It seems like this has been there since the beginning, but we haven't noticed it, because our dev app doesn't have many examples with a prefix and it always starts off from LTR and we switch it to RTL manually which doesn't have this problem since it already got a valid width while it was in LTR.

Fixes angular#18857.
mmalerba pushed a commit that referenced this issue Mar 21, 2020
…ence of a prefix (#18867)

The logic that figures out the outline gap in the presence of a prefix was producing a negative width which is invalid. It seems like this has been there since the beginning, but we haven't noticed it, because our dev app doesn't have many examples with a prefix and it always starts off from LTR and we switch it to RTL manually which doesn't have this problem since it already got a valid width while it was in LTR.

Fixes #18857.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.