Skip to content

:dir() improved support #177

Closed
Closed

Description

@brandonmcconnell

Description

"The :dir() pseudo-class in CSS allows elements to be selected based on the direction of the language, as determined in the HTML markup. There are really only two directions language can flow in a document, which are left-to-right and right-to-left. Think of this as a way to style elements that are distinguished by different language directionality."
– @geoffgraham (via CSS Tricks)

I couldn't have explained it better, myself. Thanks, Geoff 🙏🏼

Rationale

:dir() support is important to the effort of internationalization. This pseudo-class has been a long time coming and has been a topic of discussion for a while now as well:

Formal (docs-style)

Informal

Directionality can currently be set in two primary ways— setting the HTML dir attribute to either ltr or rtl, or setting the direction property in CSS to either of those same values.

Elements explicitly setting dir="rtl" (or similar) can already be targeted with CSS using an attribute selector. However, this is usually an edge case, as that property is usually set once on a document, and does not necessarily apply that same directionality to all elements on the page.

:dir() is the solution here:

  • matches [dir="rtl"] (or similar)
  • matches direction: rtl (or similar)
  • matches directionality that is either inherited or purposefully not inherited from a parent element

Specification

https://w3c.github.io/csswg-drafts/selectors-4/#the-dir-pseudo

Tests

More tests will likely be needed for this.

Activity

  1. added this to the milestone on Oct 2, 2022
  2. brandonmcconnell commented on Oct 2, 2022

    @brandonmcconnell
    Author

    @gsnedders Thanks! Is there a readme or guide (or video for that matter) to help find relevant tests like this? I have such a hard time navigating wpt.fyi sometimes, as much as I love the site and the value it adds.

    Thanks again! 🙏🏼

  3. foolip commented on Oct 3, 2022

    @foolip
    Member

    @brandonmcconnell I know wpt.fyi is very much a power user interface and there are plenty of things in hard-to-discover UI and documentation. If you have specific tasks you're trying to get done and can't, can you file an issue at https://github.com/web-platform-tests/wpt.fyi/issues?

    When it comes to finding tests, searching in a local checkout of https://github.com/web-platform-tests/wpt is probably most effective, since you can then search for the test contents, not just their names.

  4. brandonmcconnell commented on Oct 3, 2022

    @brandonmcconnell
    Author

    @foolip That's very helpful— thanks!

  5. gsnedders commented on Oct 3, 2022

    @gsnedders
    Member

    In the above case, I just started searching for "dir" and looked at where matched—that pseudo-classes (which are defined in Selectors) have tests in the Selectors directory isn't particularly surprising, given that knowledge about where they're specified.

  6. karlcow commented on Oct 4, 2022

    @karlcow

    When it comes to finding tests, searching in a local checkout of https://github.com/web-platform-tests/wpt is probably most effective, since you can then search for the test contents, not just their names.

    This. What @foolip said

    I have been experimenting a couple of times with this.
    For example for :dir(), on the repo once you have done a local clone on your computer.

    find . -name '*.html' ! -name '*-ref.html' -type f -exec grep -H ':dir(' {} \;

    which will give all matches. If you want something more browsable.

    find . -name '*.html' ! -name '*-ref.html' -type f -exec grep -H ':dir(' {} \; | sed -e 's,:.*,,' | sort | uniq | sed -e 's,^\.,https://wpt.fyi,'

    https://wpt.fyi/css/css-scoping/shadow-directionality-001.tentative.html
    https://wpt.fyi/css/css-scoping/shadow-directionality-002.tentative.html
    https://wpt.fyi/css/selectors/dir-selector-auto-direction-change-001.html
    https://wpt.fyi/css/selectors/dir-selector-auto.html
    https://wpt.fyi/css/selectors/dir-selector-change-001.html
    https://wpt.fyi/css/selectors/dir-selector-change-002.html
    https://wpt.fyi/css/selectors/dir-selector-change-003.html
    https://wpt.fyi/css/selectors/dir-selector-change-004.html
    https://wpt.fyi/css/selectors/dir-selector-ltr-001.html
    https://wpt.fyi/css/selectors/dir-selector-ltr-002.html
    https://wpt.fyi/css/selectors/dir-selector-ltr-003.html
    https://wpt.fyi/css/selectors/dir-selector-querySelector.html
    https://wpt.fyi/css/selectors/dir-selector-rtl-001.html
    https://wpt.fyi/css/selectors/dir-selector-white-space-001.html
    https://wpt.fyi/css/selectors/dir-style-01a.html
    https://wpt.fyi/css/selectors/dir-style-01b.html
    https://wpt.fyi/css/selectors/dir-style-02a.html
    https://wpt.fyi/css/selectors/dir-style-02b.html
    https://wpt.fyi/css/selectors/dir-style-03a.html
    https://wpt.fyi/css/selectors/dir-style-03b.html
    https://wpt.fyi/css/selectors/dir-style-04.html
    https://wpt.fyi/html/semantics/selectors/pseudo-classes/dir-html-input-dynamic-text.html
    https://wpt.fyi/html/semantics/selectors/pseudo-classes/dir.html
    https://wpt.fyi/html/semantics/selectors/pseudo-classes/dir01.html
    https://wpt.fyi/shadow-dom/directionality-002.tentative.html

  7. karlcow commented on Oct 4, 2022

    @karlcow

    Better suggestion from @heycam and a lot faster

    grep -lR ':dir(' | grep -v '[-]ref.html$' | sed -e 's,^\.,https://wpt.fyi,'

  8. brandonmcconnell commented on Oct 4, 2022

    @brandonmcconnell
    Author

    @karlcow @heycam Nice! I compiled that into a shell function I'll use when searching for tests from now on 👏🏼

    function find-wpt-tests(){
      cd "/path/to/wpt" # <-- replace with the path to the `wpt` directory on your local machine
      grep -lR "$@" | grep -v "[-]ref.html$" | sed -e "s,^\.,https://wpt.fyi,"
    }
    
    # usage
    find-wpt-tests ":dir("
  9. brandonmcconnell commented on Oct 5, 2022

    @brandonmcconnell
    Author

    @karlcow @heycam @gsnedders

    I put together a slightly more sophisticated version of this function ☝🏼 which handles formatting flags for the returned results and some verbiage niceties:

    • verbiage for…
      • errored state
      • loading-state
      • completed state
    • formatting flags:
      • -m for abbreviating links via markdown
      • -l for returning the results as a bulleted list

    I initially added all of that to this comment, but it became a bit too robust, so I created a separate repo for that that you can find here: find-wpt-tests

  10. moved this to Proposed in Interop 2023on Oct 7, 2022
  11. removed this from the milestone on Oct 7, 2022
  12. bkardell commented on Oct 12, 2022

    @bkardell
    Contributor

    There is also an open issue/pr about resolving these in shadow dom which would add a slew of tests when it lands web-platform-tests/wpt#29820

  13. brandonmcconnell commented on Oct 12, 2022

    @brandonmcconnell
    Author

    @bkardell Great find. Thanks, Brian!

  14. jensimmons commented on Oct 12, 2022

    @jensimmons
    Contributor

    We do want to limit potential Inteorp 2023 tests to only include ones that don't fail because an unrelated technology is not supported. For example, if the test is for :dir() + foobar, and only passes if both are supported — and foobar is not supported in all the browser engine already, then it should not be part of Interop 2023.

    Why? Because foobar isn't part of Interop 2023. (Presuming it isn't). Engines should get scored according to their :dir() implementation, not on foobar.

  15. brandonmcconnell commented on Oct 12, 2022

    @brandonmcconnell
    Author

    @jensimmons Fine point. I can see how those tests would likely be a better fit for a future shadow DOM rather than :dir()

  16. zcorpan commented on Nov 10, 2022

    @zcorpan
    Member

    More tests will likely be needed for this.

    Also see web-platform-tests/wpt#25569

  17. foolip commented on Nov 11, 2022

    @foolip
    Member

    In the State of CSS 2022 question about browser incompatibilities, there were two mentions of :dir(), so not enough to make the top list in #248. The comments were ":did(RTL)" (typo, manually identified) and ":dir() selector".

  18. foolip commented on Nov 11, 2022

    @foolip
    Member

    In the MDN short survey on CSS & HTML, "CSS :dir() pseudo-class" was selected by ~5% of survey takers, putting it in the bottom third of the 20 options. (There is some uncertainty as with any survey data.)

  19. foolip commented on Nov 17, 2022

    @foolip
    Member

    Some of the tentative tests here depend on whatwg/html#3699 / whatwg/html#7424. @meyerweb do you think that can be resolved soonish?

  20. added
    accepted
    on Feb 1, 2023
  21. foolip commented on Feb 1, 2023

    @foolip
    Member

    Thank you for proposing :dir() for gradients for inclusion in Interop 2023.

    We are pleased to let you know that this proposal was accepted as part of the CSS Pseudo-classes focus area. You can follow the progress of this Focus Area on the Interop 2023 dashboard.

    For an overview of our process, see the proposal selection summary. Thank you for contributing to Interop 2023!

    Posted on behalf of the Interop team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedfocus-area-proposal

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions