Skip to content

Commit 61034fe

Browse files
authored
docs(ByRole): Add { selected: boolean } option (#458)
1 parent ea15db8 commit 61034fe

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ getByRole(
585585
hidden?: boolean = true,
586586
name?: TextMatch,
587587
normalizer?: NormalizerFn,
588+
selected?: boolean,
588589
}): HTMLElement
589590
```
590591

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

640-
The default value can [be configured](api-configuration#configuration).
641+
The default value for `hidden` can [be configured](api-configuration#configuration).
642+
643+
Certain roles can have a selected state. You can filter the
644+
returned elements that by their selected state
645+
by setting `selected: true` or `selected: false`.
646+
647+
For example in
648+
649+
```html
650+
<body>
651+
<div role="tablist">
652+
<button role="tab" aria-selected="true">Native</button>
653+
<button role="tab" aria-selected="false">React</button>
654+
<button role="tab" aria-selected="false">Cypress</button>
655+
</div>
656+
</body>
657+
```
658+
659+
you can get the "Native"-tab by calling `getByRole('tab', { selected: true })`.
660+
To learn more about the selected state and which elements can
661+
have this state see [ARIA `aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected).
641662

642663
```html
643664
<div role="dialog">...</div>

0 commit comments

Comments
 (0)