Skip to content

Commit c47f1e6

Browse files
authored
Update guide-which-query.md (#454)
1 parent 6a26a8e commit c47f1e6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

docs/guide-which-query.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ possible. With this in mind, we recommend this order of priority:
1111

1212
1. **Queries Accessible to Everyone** queries that reflect the experience of
1313
visual/mouse users as well as those that use assistive technology
14+
1. `getByRole`: This can be used to query every element that is exposed in
15+
the
16+
[accessibility tree](https://developer.mozilla.org/en-US/docs/Glossary/AOM).
17+
With the `name` option you can filter the returned elements by their
18+
[accessible name](https://www.w3.org/TR/accname-1.1/). This should be your
19+
top preference for just about everything. There's not much you can't get
20+
with this (if you can't, it's possible your UI is inaccessible). Most
21+
often, this will be used with the `name` option like so:
22+
`getByRole('button', {name: /submit/i})`
1423
1. `getByLabelText`: Only really good for form fields, but this is the number
1524
one method a user finds those elements, so it should be your top
1625
preference.
1726
1. `getByPlaceholderText`:
1827
[A placeholder is not a substitute for a label](https://www.nngroup.com/articles/form-design-placeholders/).
1928
But if that's all you have, then it's better than alternatives.
20-
1. `getByRole`: This can be used to query every element that is exposed in
21-
the
22-
[accessibility tree](https://developer.mozilla.org/en-US/docs/Glossary/AOM).
23-
With the `name` option you can filter the returned elements by their
24-
[accessible name](https://www.w3.org/TR/accname-1.1/). This should be your
25-
top preference for interactive elements such as buttons.
2629
1. `getByText`: Not useful for forms, but this is the number 1 method a user
27-
finds most non-interactive elements (listitems or divs).
30+
finds most non-interactive elements (like divs and spans).
2831
1. `getByDisplayValue`: The current value of a form element can be useful
2932
when navigating a page with filled-in values.
3033
1. **Semantic Queries** HTML5 and ARIA compliant selectors. Note that the user

0 commit comments

Comments
 (0)