Skip to content

fix: support the <search> element in role queries - #1385

Open
FrancoKaddour wants to merge 1 commit into
testing-library:mainfrom
FrancoKaddour:fix/get-by-role-search-element
Open

fix: support the <search> element in role queries#1385
FrancoKaddour wants to merge 1 commit into
testing-library:mainfrom
FrancoKaddour:fix/get-by-role-search-element

Conversation

@FrancoKaddour

Copy link
Copy Markdown

Closes #1359

The <search> element has an implicit ARIA role of search per the HTML-AAM spec, but aria-query@5.3.0 doesn't map it. As a result getByRole('search') can't find a <search> element, and getImplicitAriaRoles returns [] for it.

The fix adds <search> in the two places that consume aria-query's maps:

  • getImplicitAriaRoles (computes an element's implicit role)
  • makeRoleSelector (builds the candidate set for a role query)

Both are gated behind a comment noting they can be removed once aria-query maps <search>. I found that patching only getImplicitAriaRoles (as in the earlier #1376) isn't enough — makeRoleSelector filters the candidate elements first, so <search> never reaches the role check. The added integration test (getByRole('search')) covers that path; there's also a unit test for getImplicitAriaRoles.

Full suite green (668 tests). #1376's contentious inert change is intentionally left out — this is only the uncontroversial <search> support.

The <search> element has an implicit ARIA role of search per the HTML-AAM
spec, but aria-query 5.3.0 does not map it, so getByRole("search") could
not find a <search> element and getImplicitAriaRoles returned [] for it.

Add <search> in the two places that consume the aria-query maps:
getImplicitAriaRoles (used to compute an element role) and makeRoleSelector
(used to build the candidate set for a role query). Both are gated behind
a comment noting they can be removed once aria-query maps <search>.

Fixes testing-library#1359
@codesandbox-ci

Copy link
Copy Markdown

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 a8714a5:

Sandbox Source
react-testing-library-examples Configuration

@FrancoKaddour

Copy link
Copy Markdown
Author

The validate failure here is the @types/node × typescript@4 typecheck breakage in node_modules/@types/node/ffi.d.ts (TS1139: Type parameter declaration expected, etc.) — not this change. The diff is source + tests only, my source has no type errors, and the full suite passes locally (668 tests). It's currently hitting other open PRs too: there's no committed lockfile, so CI installs the latest @types/node, which ships syntax typescript@^4.1.2 can't parse.

I can't re-run the workflow from a fork PR — could a maintainer give it a re-run? And happy to open a separate PR pinning @types/node (or adding an overrides entry) to the last TS4-compatible version if that'd help unblock CI repo-wide.

@FrancoKaddour

Copy link
Copy Markdown
Author

Quick update: #1386 (the @types/node pin) is now green on CI, which confirms the failure here is the unrelated @types/node × TypeScript 4 typecheck issue, not this change. Once #1386 lands, this PR's CI will pass — happy to rebase onto it if that makes review easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getByRole('search') does not find <search />

1 participant