Skip to content
Merged
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
10 changes: 5 additions & 5 deletions packages/injected/src/roleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ export function isElementHiddenForAria(element: Element): boolean {
const isOptionInsideSelect = element.nodeName === 'OPTION' && !!element.closest('select');
if (!isOptionInsideSelect && !isSlot && !isElementStyleVisibilityVisible(element, style))
return true;
return belongsToDisplayNoneOrAriaHiddenOrNonSlottedOrInert(element);
return belongsToDisplayNoneOrAriaHiddenOrNonSlotted(element);
}

function belongsToDisplayNoneOrAriaHiddenOrNonSlottedOrInert(element: Element): boolean {
function belongsToDisplayNoneOrAriaHiddenOrNonSlotted(element: Element): boolean {
let hidden = cacheIsHidden?.get(element);
if (hidden === undefined) {
hidden = false;
Expand All @@ -298,17 +298,17 @@ function belongsToDisplayNoneOrAriaHiddenOrNonSlottedOrInert(element: Element):
if (element.parentElement && element.parentElement.shadowRoot && !element.assignedSlot)
hidden = true;

// display:none and aria-hidden=true and inert are considered hidden for aria.
// display:none and aria-hidden=true are considered hidden for aria.
if (!hidden) {
const style = getElementComputedStyle(element);
hidden = !style || style.display === 'none' || getAriaBoolean(element.getAttribute('aria-hidden')) === true || element.getAttribute('inert') !== null;
hidden = !style || style.display === 'none' || getAriaBoolean(element.getAttribute('aria-hidden')) === true;
}

// Check recursively.
if (!hidden) {
const parent = parentElementOrShadowHost(element);
if (parent)
hidden = belongsToDisplayNoneOrAriaHiddenOrNonSlottedOrInert(parent);
hidden = belongsToDisplayNoneOrAriaHiddenOrNonSlotted(parent);
}
cacheIsHidden?.set(element, hidden);
}
Expand Down
26 changes: 0 additions & 26 deletions tests/library/role-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,32 +564,6 @@ test('should support search element', async ({ page }) => {
await expect.soft(page.getByRole('search', { name: 'example' })).toBeVisible();
});

test('should consider inert elements to be hidden', async ({ page }) => {
await page.setContent(`
<div aria-hidden="true">
<button type="button">First</button>
</div>
<div inert>
<button type="button">Second</button>
</div>
<button type="button" inert>Third</button>
`);

await expect(page.getByRole('button', { name: 'First' })).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Second' })).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Third' })).toHaveCount(0);

await expect(
page.getByRole('button', { name: 'First', includeHidden: true })
).toHaveCount(1);
await expect(
page.getByRole('button', { name: 'Second', includeHidden: true })
).toHaveCount(1);
await expect(
page.getByRole('button', { name: 'Third', includeHidden: true })
).toHaveCount(1);
});

function toArray(x: any): any[] {
return Array.isArray(x) ? x : [x];
}
Loading