Skip to content

getByRole doesn't respect inert when searching with hidden: true #665

@imaspen

Description

@imaspen
  • @testing-library/jest-dom version: 6.6.3
  • node version: 22.14.0
  • vitest version: 3.0.8
  • yarn version: 4.7.0

Relevant code or config:

<div role="region" aria-label="inert demo" inert></div>
expect(
  queryByRole("region", { name: "inert demo", hidden: false })
).not.toBeInTheDocument();

What you did:

Testing for an element not to be in the accessibility tree based on the presence of the inert attribute.

What happened:

getByRole returned the element, even though it should be hidden from the accessibility tree.

Reproduction:

https://codesandbox.io/p/devbox/react-testing-library-demo-forked-tg8knk

Problem description:

Elements with the inert attribute set should not be in the accessibility tree, as per the HTML standard.

Inert nodes generally cannot be focused, and user agents do not expose the inert nodes to accessibility APIs or assistive technologies.

Suggested solution:

TBD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions