testing-library / testing-library/dom-testing-library
Elements with an inert="" attribute aren't being hidden from the accessibility tree
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/domversion: 10.4.0- Testing Framework and version:
- testing-library/cypress@10.0.1
- cypress@13.17.0
- DOM Environment:
- Chrome v138
- node v22.11.0
Relevant code or config:
Codesandbox URL: https://codesandbox.io/p/sandbox/fwqv27
describe('elements hidden from the accessibility tree', () => {
it('inert elements should be hidden', () => {
cy.visit('https://fwqv27.csb.app/', { failOnStatusCode: false });
// Required to view the codesandbox preview
cy.findByRole('link', { name: 'Yes, proceed to preview' }).click();
cy.findByRole('button', { name: 'First', hidden: true }).click();
cy.findByRole('button', { name: 'Second', hidden: true }).click();
});
});
What you did:
Tried to target a button nested in a container with an inert attribute with the hidden option set to true.
What happened:
The assertion could not target the button as it isn't recognised as a hidden element.
Reproduction:
Please refer to the codesandbox URL and code snippet above.
Problem description:
According to MDN any inert elements and their children should be hidden from the accessibility tree (see source):
Specifically,
inertdoes the following:
...
- Hides the element and its content from assistive technologies by excluding them from the accessibility tree.
An example scenario from the inert HTML specification (see source):
A Document document is blocked by a modal dialog subject if subject is the topmost dialog element in document's top layer. While document is so blocked, every node that is connected to document, with the exception of the subject element and its flat tree descendants, must become inert.
It also provides a technical example in the following section (see example).
Suggested solution:
We should perform a check within the isSubtreeInaccessible method to see if the element is inside of an inert subtree:
We could potentially use the .closest() method to determine whether there is an inert ancestor (see docs):
if (element.hasAttribute('inert') || element.closest('[inert]')) {
return true;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/role-helpers.js at isSubtreeInaccessible and reproduce the issue with the provided Cypress snippet and CodeSandbox. The work is done when elements inside an inert subtree are treated as hidden from the accessibility tree.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- accessibility, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100