Skip to content

Commit 96b436f

Browse files
eps1lonalexkrolick
authored andcommitted
feat(queries): Add docs about byRole#hidden (#266)
* feat(queries): Add docs about byRole#hidden * Add example for hidden
1 parent 962dd2a commit 96b436f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ getByRole(
533533
role: TextMatch,
534534
options?: {
535535
exact?: boolean = true,
536+
hidden?: boolean = false,
536537
normalizer?: NormalizerFn,
537538
}): HTMLElement
538539
```
@@ -544,6 +545,27 @@ attribute. The
544545
[W3C HTML recommendation](https://www.w3.org/TR/html5/index.html#contents) lists
545546
all HTML elements with their default aria roles.
546547

548+
If you set `hidden` to `true` elements that are normally excluded from the
549+
accessibility tree are considered for the query as well. The default behavior
550+
follows https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion with the exception of
551+
`role="none"` and `role="presentation"` which are considered in the query in any
552+
case. For example in
553+
554+
```html
555+
<body>
556+
<main aria-hidden="true">
557+
<button>Open dialog</button>
558+
</main>
559+
<div role="dialog">
560+
<button>Close dialog</button>
561+
</div>
562+
</body>
563+
```
564+
565+
`getByRole('button')` would only return the `Close dialog`-button. To make
566+
assertions about the `Open dialog`-button you would need to use
567+
`getAllByRole('button', { hidden: true })`.
568+
547569
```html
548570
<div role="dialog">...</div>
549571
```

0 commit comments

Comments
 (0)