-
Notifications
You must be signed in to change notification settings - Fork 471
Add level
option for *ByRole('heading')
#743
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
Comments
I'd prefer Maybe |
That works for me. I wasn't sure about about having options available that don't apply to specifically to headings, but I see that I think |
I was just thinking it would be good to have this feature! 🚀
|
I'm on board with that suggestion as well 👍 |
We should probably have some validation at runtime to make sure that this option is only used with the role of heading. |
Awesome. I'm happy to take a shot at a PR for it (as long as no one wants it like tomorrow). |
I think we already do similar checks for the existing filters. Anybody that wants to work on this might want to check out #540, #692 or #729. Though I think we shouldn't throw with "aria-X is not supported" but rather with "the element cannot have X". They don't always come from aria attributes and, in the end, ARIA is just an implementation details 😉 |
Loving this idea! |
level
option for *ByRole('heading')
Closed by #757 |
Describe the feature you'd like:
Add new queries for
*ByHeadingLevel
that allow the specification of the heading level by which to query, e.g.getAllByHeadingLevel('h2')
.I know that suggestions about adding queries by tag have been rejected because they go against the user-centric testing principles, but I think this particular case is user-centric, especially for those using assistive technologies.
Suggested implementation:
Describe alternatives you've considered:
While
*ByRole('heading')
can grab the headings on the DOM, there is currently no way to specify the heading levels. And while a custom query could be made, or simply usingdocument.querySelector()
, this particular query seems like it should be a built-in as it is one of the ways that people using assistive technologies navigate web pages.Teachability, Documentation, Adoption, Migration Strategy:
Because the syntax is similar to other queries, I imagine the teachability and adoption should take minimal effort (beyond what's needed to learn any of the other queries).
Possible Documentation
ByHeadingLevel
Queries headings by their level and returns the element -- either the HTML heading element (
<h1> - <h6>
) or the element withrole="heading"
andaria-level
with matching level.Although
ByHeadingLevel
queries elements withrole="heading"
and thearia-level
attribute present, it is strongly encouraged to use the semantic HTML heading elements (<h1> - <h6>
).Note that the
ByHeadingLevel
query only supports heading levels h1-h6. While, it is possible to usearia-level
with a heading level greater than 6, it is discouraged due to inconsistent browser and assistive technology support.For example in
getByHeadingLabel('h3')
would return<h3>Drinking Coffee</h3>
.getAllByHeadingLabel('h2')
would return[<h2>What I Did Today</h2>, <h2>What I Didn't Accomplish Today</h2>]
.(...plus some reference links thrown in...)
The text was updated successfully, but these errors were encountered: