Skip to content

add accessible? option to byRole query #350

Closed
@eps1lon

Description

@eps1lon

Describe the feature you'd like:

Add a built-in method to query only accessible elements

Suggested implementation:

getByRole('listitem', { accessible: true /* default would be breaking */ })

accessible checks for:

  1. :not([aria-hidden="true"]) and no ancestor matches [aria-hidden="true"]
  2. not hidden visibility Confused it with focusability

Better: It implements https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion

Describe alternatives you've considered:

Implement custom query

Teachability, Documentation, Adoption, Migration Strategy:

Since byRole is mainly concerned about a11y it should also consider if the node in question is even accessible.

I would make this option configurable for low level tests. These elements are still displayed in the a11y pane in the chrome dev tools and are part of the a11y tree as far as I know. AT (only tested nvda+chrome, expect every AT to match that behavior) does not consider those e.g.

Strawman

<nav aria-label="breadcrumbs">
  <ol>
    <li><a /></li>
    <li aria-hidden="true">/</li>
    <li><a /></li>
  </ol>
</nav>

will be announced as a list with 2 items while the a11y tree will include 3 elements with the listitem role.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions