Skip to content

Ability to query a video and still respect the accessibility tree #1096

Open
@danny-does-stuff

Description

@danny-does-stuff

Describe the feature you'd like:

It is not possible to query for a video using the *ByRole queries, but these are the only queries which respect the accessibility tree. This means that if you have a video element that is supposed to be hidden, you cannot test it in the same way that you would test other hidden elements. Allowing other queries to opt-in to respecting the accessibility tree was discussed in #929, but this specific case of finding a video was not brought up.

Suggested implementation:

render(<div aria-hidden={true}>
   <video src="abc" aria-label="The Video" />
</div>)

expect(screen.queryByLabelText("The Video", { hidden: false } )).toBe(null)

Describe alternatives you've considered:

The current workaround would have to be something like this, where the developer would need to find the nearest parent that is hidden, which makes the tests too familiar with the layout of the html IMHO

render(<div aria-hidden={true}>
   <video src="abc" aria-label="The Video" />
</div>)

const video = screen.queryByLabelText("The Video")

expect(video.parentElement).toHaveAttribute('aria-hidden', 'true')

Teachability, Documentation, Adoption, Migration Strategy:

This would only require adding the new option hidden to all queries besides *ByRole. The option would default to true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions