Skip to content

RFC: deprecate some a11y queries #1209

@mdjastrzebski

Description

@mdjastrzebski

Problem

Some of our a11y queries are underwhelming:

  • getByA11yState({ disabled: true }) - does not give any control over which control we are trying to find. Can be problematic if there are 2+ controls with matching state, we also might accidentally match another disabled control leading to false negative result.
  • getByA11yValue({ min: 100 }) - similar issues

Note: these queries have no counterpart in RTL.

Other queries are somewhat more useful, but still less powerful than getByRole:

  • getByLabelText
  • getByHintText

Users are generally better server by using getByRole with name and state props like disabled, selected, etc.

Note: this queries have counterpart in the RTL world (LabelText) or have similar semantic (HintText).

Proposed solution

  1. Add a11y value & hint props support to getByRole in order to make it more versatile
  2. Deprecate *ByA11yState and *ByA11yValue queries, and display message to use getByRole with appropriate parameters.
  3. Keep *ByLabelText and *ByHintText text as lightweight queries, but mention in the docs that we rather suggest using getByRole with proper additional attributes.

Impact

Soft deprecating, i.e. displaying deprecating warning to console, is not a breaking change, so we might do with minor/feature update.

We then should remove *ByA11yState and *ByA11yValue in the next or next^2 release.

Metadata

Metadata

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