Skip to content
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

feat(ByRole): Allow filter by disabled state #1231

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/queries/byrole.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ getByRole(
pressed?: boolean,
suggest?: boolean,
current?: boolean | string,
disabled?: boolean,
expanded?: boolean,
queryFallbacks?: boolean,
level?: number,
Expand Down Expand Up @@ -164,6 +165,28 @@ the "👎" by calling `getByRole('link', { current: false })`. To learn more abo
the current state see
[ARIA `aria-current`](https://www.w3.org/TR/wai-aria-1.2/#aria-current).

### `disabled`

You can filter elements by their disabled state by setting `disabled: true` or
`disabled: false`.

For example in

```html
<body>
<section>
<button disabled>Login</button>
<div role="alert" aria-disabled="false">Failed to login</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the aria-disabled here seems a bit confusing to me.
Are we also filtering by aria-disabled or just by the disabled attribute? I think that we should explain it here so people will have a clear understanding.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're filtering by things that are disabled according to the a11y tree. This applies to every filter option in ByRole.

This here includes examples.

How would you explain it do avoid confusions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</section>
</body>
```

you can get the "Login" button by calling
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
you can get the "Login" button by calling
You can get the "Login" button by calling `getByRole('button', { disabled: true })` and the alert by calling `getByRole('alert', { disabled: false })`.

`getByRole('button', { disabled: true })`. To learn more about the disabled
state see
[ARIA `aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed) and
[MDN `disabled` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled).

### `pressed`

Buttons can have a pressed state. You can filter the returned elements by their
Expand Down