fix: support inert attribute and <search> element in role queries#1376
fix: support inert attribute and <search> element in role queries#1376mixelburg wants to merge 1 commit into
Conversation
- Add inert attribute check to isSubtreeInaccessible, so elements inside inert subtrees are correctly excluded from the a11y tree. Fixes testing-library#1364. - Add <search> element implicit role mapping (search), since aria-query 5.3.0 does not yet include this HTML-ARIA mapping. Fixes testing-library#1359.
|
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 7451bae:
|
|
Nice! I think I'll have a use case for this soon so might try it out via patching the main package |
|
Although have you seen the history on #1366? @eps1lon had some concerns about how That said, for my use case this will probably be fine, so I'll probably still apply the patch. |
|
Closing due to inactivity. The reviewer raised valid concerns about dialog/inert interaction that need further investigation. Happy to reopen with a revised approach. |
Summary
This PR addresses two related issues in role-based queries:
1.
inertattribute not hiding elements from a11y tree (#1364)Elements with the
inertattribute (and their descendants) should be excluded from the accessibility tree. Per the HTML spec,inertmakes the element and all its contents hidden from assistive technologies.Fix: Added a check in
isSubtreeInaccessiblethat returnstruewhen:inertattribute, ORinertattribute (viaelement.closest('[inert]'))2.
<search>element not found bygetByRole('search')(#1359)The
<search>HTML element has an implicit ARIA role ofsearchper the HTML-ARIA spec, butaria-query@5.3.0does not include this mapping in itselementRolesmap.Fix: Added a fallback in
getImplicitAriaRolesthat returns[search]for<search>elements. This workaround can be removed oncearia-querypublishes a version that includes this mapping (the mapping exists in aria-query'smainbranch but is not yet released).Test plan
<div inert />to the existingshouldExcludeFromA11yTreetest matrix<search>element implicit role29 passed, 29 totalRelated issues
getByRole('search')does not find<search />#1359