Skip to content

Custom labels #2

Description

@mrego

Thinking about the topic from yesterday AOM meeting where we talked about Custom labels.

Doing some tests if we have the following example:

<x-label1 id="label1">
  <template shadowroot="open">
    <span id="foo">foo</span>
    <span id="bar">bar</span>
    <span id="baz">baz</span>
  </template>
</x-label1>
<input id="input1" aria-labelledby="label1" />

We get "foo bar baz" as label for the <input>. That's because how accessible name computation is done (which includes all children): https://w3c.github.io/accname/#mapping_additional_nd_te

With the current reflection proposal in this repo we could be more specified and just select one of the elements as the label:

<x-label1 id="label1">
  <template shadowroot="open" reflectsAriaLabelledBy>
    <span id="foo">foo</span>
    <span id="bar" reflectAriaLabelledBy>bar</span>
    <span id="baz">baz</span>
  </template>
</x-label1>
<input id="input1" aria-labelledby="label1" />

That way, we'll get "bar" as label for the <input>.

One question is if we could do something like this:

<x-label1 id="label1">
  <template shadowroot="open">
    <div aria-labelledby="bar">
      <span id="foo">foo</span>
      <span id="bar">bar</span>
      <span id="baz">baz</span>
    </div>
  </template>
</x-label1>
<input id="input1" aria-labelledby="label1" />

And tweak accessible name computation for custom elements, so it checks the first child for example, and use the information there. So in this example it ends up going to the bar element.

Currently accessible name computation doesn't work like that for regular elements, in order to avoid infinite loops while getting the element. Somehow with ARIA attribute reflection we can reference elements outside the Shadow DOM (see leobalter#15), so we could have a loop there too, maybe we should set some kind of condition anyway and do it only once for the first child of the custom element or something like that.

Anyway without entering in the final details, would this make any sense?

And going even further, would this proposal work for other things (unrelated to accessible name calculation), so we could do something like:

<input id="input" aria-activedescendant="list" />
<x-list id="list">
  <template shadowroot="open">
    <ul aria-activedescendant="i2">
      <li id="i1">item 1</li>
      <li id="i2">item 2</li>
      <li id="i3">item 3</li>
    </ul>
  </template>
</x-list>

WDYT?

CC @joanmarie

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions