Skip to content

getByRole should support fallback roles #411

Closed
@devongovett

Description

@devongovett

The *ByRole query should support querying elements that have multiple role values defined. the ARIA spec defines the role attribute as a whitespace delimited list of values, of which the engine will choose the first supported value. See https://www.w3.org/TR/wai-aria-1.2/#introroles. Querying by role when testing should take this into account and find roles matching any of the items in the list rather than only the entire role attribute.

Relevant code or config:

let {getByRole} = render(<div role="meter progressbar" />);
getByRole('meter'); // throws
getByRole('progressbar'); // throws
getByRole('meter progressbar'); // returns the div

Suggested solution:

Possibly split the role string here and match against any of the values. I'd be happy to implement this if it's agreed upon. It's unclear to me whether that would be considered a breaking change.

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