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 aria-current state #943

Merged

Conversation

savcni01
Copy link
Contributor

@savcni01 savcni01 commented May 5, 2021

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:

  • Documentation added to the
    docs site - see this docs PR
  • Tests
  • Typescript definitions updated
  • Ready to be merged

 - add current to byRoleOptions
 - add role option and helper
 - add tests for new option
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 5, 2021

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:

Sandbox Source
react-testing-library-examples Configuration

* 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
Copy link
Member

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?

Copy link
Contributor Author

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:

  1. Merge current implementation and open additional issue to improve/enhance it to yu
  2. Fix it right here in this MR. I think it preferred way. I'll try to do it on weekend.

Thanks for the feedback.

Copy link
Member

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 } ).

@savcni01 savcni01 changed the title feat(byRole): add aria-current option for byRole queries (issue 864) feat(byRole): add aria-current option for byRole queries (fix #864) May 5, 2021
@eps1lon eps1lon changed the title feat(byRole): add aria-current option for byRole queries (fix #864) feat(byRole): add aria-current option for byRole queries May 10, 2021
@eps1lon
Copy link
Member

eps1lon commented Aug 25, 2021

  1. Updated branch
  2. Use explicit values instead of casting to true | false as discussed in feat(ByRole): Allow filter by aria-current state #943 (comment)
  3. aria-current defaults to false if omitted
  4. Drop test for unsupported roles as there are none

@eps1lon eps1lon changed the title feat(byRole): add aria-current option for byRole queries feat(ByRole): add aria-current option for byRole queries Aug 25, 2021
@eps1lon eps1lon changed the title feat(ByRole): add aria-current option for byRole queries feat(ByRole): Allow filter by aria-current state Aug 25, 2021
@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #943 (4fabb81) into main (d03f4f6) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #943   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          916       924    +8     
  Branches       284       289    +5     
=========================================
+ Hits           916       924    +8     
Flag Coverage Δ
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (ø)
node-16 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/queries/role.js 100.00% <100.00%> (ø)
src/role-helpers.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d03f4f6...4fabb81. Read the comment docs.

src/role-helpers.js Outdated Show resolved Hide resolved
types/queries.d.ts Outdated Show resolved Hide resolved
@eps1lon eps1lon added the enhancement New feature or request label Aug 25, 2021
@eps1lon eps1lon merged commit fbbb29a into testing-library:main Aug 25, 2021
@eps1lon
Copy link
Member

eps1lon commented Aug 25, 2021

@all-contributors add @savcni01 for code

@allcontributors
Copy link
Contributor

@eps1lon

I've put up a pull request to add @savcni01! 🎉

@eps1lon
Copy link
Member

eps1lon commented Aug 25, 2021

@savcni01 Much appreciated, thanks!

@github-actions
Copy link

🎉 This PR is included in version 8.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getByRole(role, { current: true })
3 participants