From ea28919f9f318b77d70c6079e13adac26e039126 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Fri, 25 Oct 2024 11:00:39 -0700 Subject: [PATCH] fix(overlays): remove aria hidden if last overlay is not toast --- core/src/utils/overlays.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/utils/overlays.ts b/core/src/utils/overlays.ts index 1e6ec63701a..f932a3cff3b 100644 --- a/core/src/utils/overlays.ts +++ b/core/src/utils/overlays.ts @@ -639,13 +639,26 @@ export const dismiss = async ( return false; } - const lastOverlay = doc !== undefined && getPresentedOverlays(doc).length === 1; + /** + * For accessibility, toasts lack focus traps and don’t receive + * `aria-hidden` on the root element when presented. + * + * All other overlays use focus traps to keep keyboard focus + * within the overlay, setting `aria-hidden` on the root element + * to enhance accessibility. + * + * Therefore, we must remove `aria-hidden` from the root element + * when the last non-toast overlay is dismissed. + */ + const overlaysNotToast = doc !== undefined ? getPresentedOverlays(doc).filter((o) => o.tagName !== 'ION-TOAST') : []; + + const lastOverlayNotToast = overlaysNotToast.length === 1 && overlaysNotToast[0].id === overlay.el.id; /** - * If this is the last visible overlay then - * we want to re-add the root to the accessibility tree. + * If this is the last visible overlay that is not a toast + * then we want to re-add the root to the accessibility tree. */ - if (lastOverlay) { + if (lastOverlayNotToast) { setRootAriaHidden(false); document.body.classList.remove(BACKDROP_NO_SCROLL); }