Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Revert "fix(a11y): track inert elements as hidden (#36947)" (#37137)

Adam Gastineau0aa4cd895606
diff --git a/packages/injected/src/roleUtils.ts b/packages/injected/src/roleUtils.ts
index 3f0b5c14d6..e652ee8c15 100644
--- a/packages/injected/src/roleUtils.ts
+++ b/packages/injected/src/roleUtils.ts
@@ -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;
@@ -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);
}
diff --git a/tests/library/role-utils.spec.ts b/tests/library/role-utils.spec.ts
index 796bad3f3b..d894edbb29 100644
--- a/tests/library/role-utils.spec.ts
+++ b/tests/library/role-utils.spec.ts
@@ -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];
}