Skip to content

feat(ByRole): Allow filter by selected state #540

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

Merged
merged 3 commits into from
May 6, 2020

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented May 3, 2020

What:

Allows to filter results of ByRole by their aria-selected state via getByRole(role, { selected: true }).

There were some concerns allowing filtering by aria attributes (can't find the issue anymore) since users could mistakenly add them arbitrarily to create selectors that look accessible while creating broken UIs.

This is why I think we should restrict filter options to attributes that are only allowed on certain roles. For example, I wouldn't implement getByRole(role, { disabled: true }) since aria-disabled is a global attribute i.e. can be applied to any element1. If people want to filter by aria attributes on arbitrary elements then they always have the getAllByRole(...).filter() escape hatch.

1 I was looking at aria-disabled in ARIA 1.1. It is restricted to certain elements in 1.2. The gist still applies.

Why:

Spec-compliant convenience wrapper around getAllByRole(role).filter(el => el.getAttribute('aria-selected') === "true")

How:

  • consider implicit and explicit value of aria-selected
  • reject selected if the role does not support this attribute

Checklist:

@eps1lon eps1lon added the enhancement New feature or request label May 3, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 3, 2020

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 62928cf:

Sandbox Source
flamboyant-sara-1b5sj Configuration

@codecov
Copy link

codecov bot commented May 3, 2020

Codecov Report

Merging #540 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #540   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines          438       452   +14     
  Branches       105       111    +6     
=========================================
+ Hits           438       452   +14     
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 9d62141...62928cf. Read the comment docs.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

I like where this is going 👍 Just one question

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Sweet! Let's get docs ready and then we can get this merged.

@kentcdodds kentcdodds merged commit 752ff66 into testing-library:master May 6, 2020
@kentcdodds
Copy link
Member

🎉 This PR is included in version 7.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@eps1lon eps1lon deleted the feat/aria-selector branch July 22, 2020 10:05
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.

2 participants