Skip to content

Commit f8ad6c3

Browse files
idanennickserv
andauthored
docs(ByRole): Add { checked: boolean } option (#525)
Co-authored-by: Nick McCurdy <[email protected]>
1 parent af198d6 commit f8ad6c3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/dom-testing-library/api-queries.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ getByRole(
605605
name?: TextMatch,
606606
normalizer?: NormalizerFn,
607607
selected?: boolean,
608+
checked?: boolean,
608609
queryFallbacks?: boolean,
609610
}): HTMLElement
610611
```
@@ -684,6 +685,29 @@ you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
684685
To learn more about the selected state and which elements can have this state
685686
see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
686687

688+
Certain roles can have a checked state. You can filter the returned elements by
689+
their checked state by setting `checked: true` or `checked: false`.
690+
691+
For example in
692+
693+
```html
694+
<body>
695+
<section>
696+
<button role="checkbox" aria-checked="true">Sugar</button>
697+
<button role="checkbox" aria-checked="false">Gummy bears</button>
698+
<button role="checkbox" aria-checked="false">Whipped cream</button>
699+
</section>
700+
</body>
701+
```
702+
703+
you can get the "Sugar" option by calling
704+
`getByRole('checkbox', { checked: true })`. To learn more about the checked
705+
state and which elements can have this state see
706+
[ARIA `aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked).
707+
708+
> **Note:** Checkboxes have a "mixed" state, which is considered neither checked
709+
> nor unchecked (details [here](https://www.w3.org/TR/html-aam-1.0/#details-id-56)).
710+
687711
```html
688712
<div role="dialog">...</div>
689713
```

0 commit comments

Comments
 (0)