Skip to content

feat(ByRole): Allow filter by value state #1230

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 4 commits into from
Mar 24, 2023
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
69 changes: 69 additions & 0 deletions docs/queries/byrole.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ getByRole(
expanded?: boolean,
queryFallbacks?: boolean,
level?: number,
value?: {
min?: number,
max?: number,
now?: number,
text?: TextMatch,
}
}): HTMLElement
```

Expand Down Expand Up @@ -321,6 +327,69 @@ To learn more about the `aria-level` property, see
> The `level` option is _only_ applicable to the `heading` role. An error will
> be thrown when used with any other role.

### `value`

A range widget can be queried by any value `getByRole('heading')` or by a
specific value using the `level` option
`getByRole('spinbutton', { value: { now: 5, min: 0, max: 10, text: 'medium' } })`.

Note that you don't have to specify all properties in `value`. A subset is
sufficient e.g. `getByRole('heading', { value: { now: 5, text: 'medium' } })`.

Given the example below,

```html
<body>
<section>
<button
role="spinbutton"
aria-valuenow="5"
aria-valuemin="0"
aria-valuemax="10"
aria-valuetext="medium"
>
Volume
</button>
<button
role="spinbutton"
aria-valuenow="3"
aria-valuemin="0"
aria-valuemax="10"
aria-valuetext="medium"
>
Pitch
</button>
</section>
</body>
```

you can query specific spinbutton(s) with the following queries,

```js
getByRole('heading', {value: {now: 5}})
// <button>Volume</button>

getAllByRole('heading', {value: {min: 0}})
// [
// <button>Volume</button>,
// <button>Pitch</button>
// ]
```

> Every specified property in `value` must match. For example, if you query for
> `{value: {min: 0, now: 3}}` `aria-valuemin` must be equal to 0 **AND**
> `aria-valuenow` must be equal to 3

> The `value` option is _only_ applicable to certain roles (check the linked MDN
> pages below for applicable roles). An error will be thrown when used with any
> other role.

To learn more about the `aria-value*` properties, see
[MDN `aria-valuemin`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-valuemin),
[MDN `aria-valuemax`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-valuemax),
[MDN `aria-valuenow`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-valuenow),
[MDN `aria-valuetext`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-valuetext).

### `description`

You can filter the returned elements by their
Expand Down