Skip to content

docs(ByRole): Add { selected: boolean } option #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion docs/dom-testing-library/api-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ getByRole(
hidden?: boolean = true,
name?: TextMatch,
normalizer?: NormalizerFn,
selected?: boolean,
}): HTMLElement
```

Expand Down Expand Up @@ -637,7 +638,27 @@ case. For example in
assertions about the `Open dialog`-button you would need to use
`getAllByRole('button', { hidden: true })`.

The default value can [be configured](api-configuration#configuration).
The default value for `hidden` can [be configured](api-configuration#configuration).

Certain roles can have a selected state. You can filter the
returned elements that by their selected state
by setting `selected: true` or `selected: false`.

For example in

```html
<body>
<div role="tablist">
<button role="tab" aria-selected="true">Native</button>
<button role="tab" aria-selected="false">React</button>
<button role="tab" aria-selected="false">Cypress</button>
</div>
</body>
```

you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
To learn more about the selected state and which elements can
have this state see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).

```html
<div role="dialog">...</div>
Expand Down