[go: up one dir, main page]

Page MenuHomePhabricator

Explore using :where() for [dir] selectors on docs site
Open, Needs TriagePublic

Description

On the docs site and the sandbox, we use postcss-rtlcss, which prefixes selectors for direction-specific rules with [dir="ltr"] or [dir="rtl"]. It also prefixes selectors for potentially direction-sensitive rules with [dir], to avoid a specificity issue where a flipped rule accidentally has a higher specificity than a non-flipped rule. However, in https://gerrit.wikimedia.org/r/c/design/codex/+/1029216 we discovered another issue, where adding /*rtl:ignore*/ can also cause specificity issues.

To reduce specificity issues and also reduce how our CSS is mangled in general, we should consider using :where(). Specifically, we would configure postcss-rtlcss to:

  • Use :where( [dir="ltr"] ) instead of [dir="ltr"]
  • Use :where( [dir="rtl"] ) instead of [dir="rtl"]
  • Not use [dir] at all

This should eliminate specificity issues, since the specificity of a :where() expression is 0. MDN says that :where() is supported in all browsers released after January 2021, so there shouldn't be any browser support issues (and also this only affects the doc site and the sandbox, not the library itself).

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Now that :dir() is finally available in all browsers (since December 2023), maybe we could bypass this entirely, and use :dir( ltr ) and :dir( rtl ) instead. That would solve a lot more problems: it would eliminate the need to carefully manage dir attributes, and would support nested directionality.

Change #1068259 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] docs: Use `:dir(rtl)` instead of `[dir="rtl"]` for directional styles

https://gerrit.wikimedia.org/r/1068259