w3c / accname

Accessible Name and Description Computation
https://w3c.github.io/accname/
61 stars 23 forks source link

Use aria-label when computing name of hidden elements #144

Closed jaragunde closed 3 years ago

jaragunde commented 3 years ago

I'm reporting a case that I came up when implementing the proposal in PR #137, related to the discussion in #57, in Chromium.

When the hidden element which is a target of an aria-labelledby relation has the aria-label property, it might be preferable to use that instead of innerText. An example, based on an existing Chromium test:

<html>
<style>
  .hide {
    visibility: hidden;
  }
  .visible {
    visibility: visible;
  }
</style>
<body>
  <div>
      <span role="group" class="visible" id="test" aria-labelledby="a4">
        <span class="hide" aria-label="span-A4" id="a4"></span>
      </span>
  </div>
</body>
</html>

The name of the node with id="test" used to be 'span-A4', but after implementing the PR #137 proposal, the name is empty.

cookiecrook commented 3 years ago

Seems reasonable to special case aria-label.

What would you expect to happen in the case of an empty aria-label, rather than a missing attribute? Would this step result in "" or "contents"?

<span hidden id="foo" aria-label="">contents</span>

Update: I discussed with @accdc. There is already precedent for ignoring empty aria-label, so this step should return the "contents" innerText.

cookiecrook commented 3 years ago

Something like this?

-<li>If the <code>current node</code> is <a class="termref">hidden</a>, compute the text alternative of the <code>current node</code> by returning {{HTMLElement/innerText}} of the node.</li>
+<li>If the <code>current node</code> is <a class="termref">hidden</a>:
+  <ol>
+    <li>If the <code>current node</code> has an <a class="pref">aria-label</a> attribute whose value, when trimmed of white space, is not the empty string, return the value of <a class="pref">aria-label</a>.</li>
+    <li>Otherwise, compute the text alternative of the <code>current node</code> by returning the {{HTMLElement/innerText}} of the node.</li>
+  </ol>
+</li>
aleventhal commented 3 years ago

@cookiecrook +1

This will reduce the chances that we will break existing content, and is reasonably simple and intuitive.

cookiecrook commented 3 years ago

Assuming @jaragunde and @accdc will like this change, so I've added it as a change suggestion to PR #137. Once the change is pulled in there, this issue #144 can be closed.

cookiecrook commented 3 years ago

Closing since that's now part of #137. Re-open if needed. Thanks @jaragunde and @aleventhal.

jaragunde commented 3 years ago

Thanks to you for shaping this suggestion into the proposed text!