Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/__tests__/role-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ test.each([
['<div style="display: none;"/>', true],
['<div style="visibility: hidden;"/>', true],
['<div aria-hidden="true" />', true],
['<div inert />', true],
])('shouldExcludeFromA11yTree for %s returns %p', (html, expected) => {
const {container} = render(html)
container.firstChild.appendChild(document.createElement('button'))
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ test('by default excludes elements which have aria-hidden="true" or any of their
`)
})

test('by default excludes elements which have inert attribute or any of their parents', () => {
const {getByRole} = render('<div inert><ul /></div>')

expect(() => getByRole('list')).toThrowErrorMatchingInlineSnapshot(`
Unable to find an accessible element with the role "list"

There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the \`hidden\` option to \`true\`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole

Ignored nodes: comments, script, style
<div>
<div
inert=""
>
<ul />
</div>
</div>
`)
})

test('considers the computed visibility style not the parent', () => {
// this behavior deviates from the spec which includes "any descendant"
// if visibility is hidden. However, chrome a11y tree and nvda will include
Expand Down
4 changes: 4 additions & 0 deletions src/role-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function isSubtreeInaccessible(element) {
return true
}

if (element.hasAttribute('inert')) {
return true
}

const window = element.ownerDocument.defaultView
if (window.getComputedStyle(element).display === 'none') {
return true
Expand Down