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

Accessibility: children presentational true element nesting another control injected via JavaScript #161

Open
giacomo-petri opened this issue Dec 27, 2024 · 0 comments

Comments

@giacomo-petri
Copy link

Nested button elements are exposed inconsistently across browsers, whether implemented using HTML+JS or managed with ARIA alone.

Example: https://codepen.io/Giacomo-Petri/pen/bNbrWxz

ARIA version

<div role="button">
  <span>outer button</span>
  <span role="button">Inner button</span>
</div>

HTML + JS version

<div id="button-container">
  <button id="outer-button">
    <span>outer button</span>
    <span id="inner-button-container"></span>
  </button>
</div>

<script>
    const innerButton = document.createElement("button");
    innerButton.textContent = " (inner button)";
    document.getElementById("inner-button-container").appendChild(innerButton);
</script>

ARIA version and HTML+JS version behave inconsistently:

  • ARIA version: According to ARIA specs 7.1 Excluding Elements from the Accessibility Tree:

    user agents SHOULD NOT include the following elements in the accessibility tree: ... Any descendants of elements that have the characteristic "Children Presentational: True" unless the descendant is not allowed to be presentational because it meets one of the conditions for exception described in Presentational Roles Conflict Resolution. However, the text content of any excluded descendants is included.

    In this case, the inner button should be excluded because its ancestor has presentational children. The inner button doesn't fall under a roles conflict resolution exception. Although it has role="button", it is not focusable and thus is treated as presentational.

    • Browsers:
      • Chromium and Gecko expose the nested button role, but per specs the SHOULD NOT
      • WebKit ignores the button role, as per specs.
  • HTML version:

    If an element is focusable, user agents MUST ignore the none/presentation role and expose the element with its implicit role, in order to ensure that the element is operable.

    In this version, the nested button is focusable by default. Because it is focusable, it falls under the roles conflict resolution exception, and its role as a button is exposed.

    • Browsers:
      • Chromium and Gecko expose the button role, as per specs
      • WebKit ignores the button role, but per roles conflict resolution rule in ARIA specs, it shouldn't.

Note: ref ARIA issue #2406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant