Skip to content

docs(ByRole): Add { pressed: boolean } option for querying by aria-pressed state #551

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
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
34 changes: 30 additions & 4 deletions docs/dom-testing-library/api-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ getByRole(
normalizer?: NormalizerFn,
selected?: boolean,
checked?: boolean,
pressed?: boolean,
queryFallbacks?: boolean,
}): HTMLElement
```
Expand Down Expand Up @@ -677,8 +678,10 @@ assertions about the `Open dialog`-button you would need to use
The default value for `hidden` can
[be configured](api-configuration#configuration).

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

You can filter the returned elements by their selected state by setting
`selected: true` or `selected: false`.

For example in

Expand All @@ -696,8 +699,10 @@ 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`.
#### `checked`

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

For example in

Expand All @@ -720,6 +725,27 @@ state and which elements can have this state see
> nor unchecked (details
> [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).

#### `pressed`

Buttons can have a pressed state. You can filter the returned elements by
their pressed state by setting `pressed: true` or `pressed: false`.

For example in

```html
<body>
<section>
<button aria-pressed="true">👍</button>
<button aria-pressed="false">👎</button>
</section>
</body>
```

you can get the "👍" button by calling
`getByRole('button', { pressed: true })`. To learn more about the pressed
state see
[ARIA `aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed).

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