-
Notifications
You must be signed in to change notification settings - Fork 470
feat(ByRole): Allow filter by aria-current
state
#943
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 aria-current
state
#943
Conversation
- add current to byRoleOptions - add role option and helper - add tests for new option
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4fabb81:
|
- docs for PR: testing-library/dom-testing-library#943 - according to issue: testing-library/dom-testing-library#864
types/queries.d.ts
Outdated
* If true only includes elements in the query set that are marked as | ||
* current in the accessibility tree, i.e., `aria-current="true"` | ||
*/ | ||
current?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather just query against exact values. Then we automatically support newly introduced values. It's not clear to me that you want aria-current="page"
to match against current: true
as well as aria-current="date"
. Would people actually want aria-current="page"
and aria-current="date"
in a getAllByRole(role, { current: true })
query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was one of the solution suggestions at the original issue. Both suggestions have it pros and cons.
Now we have two options:
- Merge current implementation and open additional issue to improve/enhance it to yu
- Fix it right here in this MR. I think it preferred way. I'll try to do it on weekend.
Thanks for the feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge current implementation and open additional issue to improve/enhance it to yu
That wouldn't be an enhancement though. The proposals are incompatible. Let's go with my simpler, more robust proposal and then see if people actually need [aria-current="page"], [aria-current="date"]
via ByRole(role, { current: true } )
.
It's unclear if we want to cast them to `true | false`
|
aria-current
state
Codecov Report
@@ Coverage Diff @@
## main #943 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 916 924 +8
Branches 284 289 +5
=========================================
+ Hits 916 924 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@all-contributors add @savcni01 for code |
I've put up a pull request to add @savcni01! 🎉 |
@savcni01 Much appreciated, thanks! |
🎉 This PR is included in version 8.2.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
According to fix #864 issue, this PR adds
aria-current
attribute to byRole queries options.Since
aria-current
may be used in different ways e.g aria-current="page", aria-current="location", aria-current="step" we may consider making the option take a string like:getByRole("button", { current: "page" })
but so far this RR implemented another sufficient variant:
getByRole("button", { current: true })
checking only the existence of the aria-current attribute as it's unlikely more than one type is being tested at a time.
Checklist:
docs site - see this docs PR