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

"HTMLElement.dir": Misleading info about how the value is determined #14484

Open
jwdallas opened this issue Mar 30, 2022 · 1 comment
Open

"HTMLElement.dir": Misleading info about how the value is determined #14484

jwdallas opened this issue Mar 30, 2022 · 1 comment
Labels
area: DOM/CSSOM Content:WebAPI Web API docs effort: small This task is a small effort. help wanted If you know something about this topic, we would love your help!

Comments

@jwdallas
Copy link

MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dir

What information was incorrect, unhelpful, or incomplete?

When an element has its dir set to "auto", the direction of the element is determined based on its first strong directionality character, or default to the directionality of its parent element.

  1. This a little confusing since I think it's referring to the dir attribute not the API but it doesn't actually specify.
  2. Setting the dir attribute does not update the value of this API in the way mentioned. The API simply returns "auto".

What did you expect to see?

Maybe a note explaining that this API can't be used to determine the current direction of an element. You’ll need to use getComputedStyle for that.

MDN Content page report details
@github-actions github-actions bot added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Mar 30, 2022
@sideshowbarker sideshowbarker changed the title Issue with "HTMLElement.dir": (Misleading info about how the value is determined) Mar 31, 2022
@sideshowbarker sideshowbarker added help wanted If you know something about this topic, we would love your help! Content:HTML Hypertext Markup Language docs effort: small This task is a small effort. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Mar 31, 2022
@sideshowbarker sideshowbarker added Content:WebAPI Web API docs and removed Content:HTML Hypertext Markup Language docs labels Apr 27, 2022
@tlylt
Copy link
Contributor

tlylt commented Feb 1, 2023

Hi @jwdallas, regarding the confusion above:

When an element has its dir set to "auto", the direction of the element is determined based on its first strong directionality character, or default to the directionality of its parent element.

  1. This a little confusing since I think it's referring to the dir attribute not the API but it doesn't actually specify.

I suppose it refers to both the dir attribute and how you can get or set it. Is the getting and setting what you refer to as "the API" ? In the very first paragraph of the page, it is stated that:

The HTMLElement.dir property gets or sets the text writing directionality of the content of the current element.

Does that clarify?


Setting the dir attribute does not update the value of this API in the way mentioned. The API simply returns "auto".

Is there a reproduction code snippet that you can provide?

  • if it is set as values such as rtl, it will return rtl
  • if it is set as auto, it should reasonably return auto? (I tested and it does return auto)

Are you saying if it is set as auto, the element.dir should get back the value that it infers instead (so, perhaps rtl if its parent has rtl)? I'm not sure that should be the right behavior because the attribute itself is auto and should remain so.

I have constructed an example (also hosted here) below, you can try it out or modify the example to illustrate your point, so that I can help clarify further?

    <p id="target">This is my target</p>
    <p id="before"></p>
    <p id="after"></p>
    <script>
      const target = document.getElementById('target');
      const before = document.getElementById('before');
      const after = document.getElementById('after');
      before.textContent = `The original dir is: ${target.dir}`; // initially empty
      target.dir = 'rtl'; // change the text direction on a paragraph identified as "target"
      console.log(target.dir); // "rtl"
      after.textContent = `The updated dir is: ${target.dir}`; // "The updated dir is: rtl"
    </script>

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DOM/CSSOM Content:WebAPI Web API docs effort: small This task is a small effort. help wanted If you know something about this topic, we would love your help!
5 participants