Skip to content

docs(ByRole): Add { checked: boolean } option #525

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 3 commits into from
Jul 15, 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
24 changes: 24 additions & 0 deletions docs/dom-testing-library/api-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ getByRole(
name?: TextMatch,
normalizer?: NormalizerFn,
selected?: boolean,
checked?: boolean,
queryFallbacks?: boolean,
}): HTMLElement
```
Expand Down Expand Up @@ -684,6 +685,29 @@ 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).

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

For example in

```html
<body>
<section>
<button role="checkbox" aria-checked="true">Sugar</button>
<button role="checkbox" aria-checked="false">Gummy bears</button>
<button role="checkbox" aria-checked="false">Whipped cream</button>
</section>
</body>
```

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

> **Note:** Checkboxes have a "mixed" state, which is considered neither checked
> nor unchecked (details [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).

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