Skip to content

fix(material/form-field): support a different direction than the page - #34081

Open
Ahmed7991 wants to merge 1 commit into
angular:mainfrom
Ahmed7991:form-field-ltr-in-rtl
Open

Ahmed7991 wants to merge 1 commit into
angular:mainfrom
Ahmed7991:form-field-ltr-in-rtl

Conversation

@Ahmed7991

Copy link
Copy Markdown

The form field styles used [dir='rtl'] selectors, which match any ancestor with dir="rtl". This meant that a form field with dir="ltr" inside an RTL page still got the RTL styles: the outline lost its leading border and the label, padding and native select arrow were placed for RTL.

These changes switch the styles to logical properties, so they follow the direction of the form field itself. transform-origin and clip-path have no logical equivalents, so those two rules use :dir(rtl), which also resolves against the closest element with a dir attribute.

Measured in an Angular 22.2 / Material 22.2.6 app (Chromium and Firefox), label offset from the start edge of a dir="ltr" field inside a dir="rtl" page:

Before After Plain LTR page
Outline 29px 16px 16px
Fill 65px 52px 52px
Native select 33px 16px 16px
Outline leading border 0px 1px 1px

Fields in a plain RTL page measure the same before and after.

Fixes #26778.

The form field styles used `[dir=rtl]` selectors, which match any ancestor with `dir="rtl"`. This meant that a form field with `dir="ltr"` inside an RTL page still got the RTL styles: the outline lost its leading border and the label, padding and native select arrow were placed for RTL.

These changes switch the styles to logical properties, so they follow the direction of the form field itself. `transform-origin` and `clip-path` have no logical equivalents, so those two rules use `:dir(rtl)`, which also resolves against the closest element with a `dir` attribute.

Fixes angular#26778.

This branch has not been deployed

No deployments
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 MatFormFields: Force LTR in RTL page

1 participant