From 6ac77855cfd2ca0dd2386dd861a1d3ea696adb5c Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Thu, 21 Aug 2025 08:36:41 -0700 Subject: [PATCH] Revert "fix(a11y): track inert elements as hidden (#36947)" This reverts commit 6e3392bf5e8839c5a88daa79befff42c5c85202a. --- packages/injected/src/roleUtils.ts | 10 +++++----- tests/library/role-utils.spec.ts | 26 -------------------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/packages/injected/src/roleUtils.ts b/packages/injected/src/roleUtils.ts index 3f0b5c14d601c..e652ee8c1581a 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 796bad3f3bcbd..d894edbb29f31 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(` - -
- -
- - `); - - 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]; }