Skip to content

Commit ea28919

Browse files
committed
fix(overlays): remove aria hidden if last overlay is not toast
1 parent 33be9ff commit ea28919

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

core/src/utils/overlays.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,26 @@ export const dismiss = async <OverlayDismissOptions>(
639639
return false;
640640
}
641641

642-
const lastOverlay = doc !== undefined && getPresentedOverlays(doc).length === 1;
642+
/**
643+
* For accessibility, toasts lack focus traps and don’t receive
644+
* `aria-hidden` on the root element when presented.
645+
*
646+
* All other overlays use focus traps to keep keyboard focus
647+
* within the overlay, setting `aria-hidden` on the root element
648+
* to enhance accessibility.
649+
*
650+
* Therefore, we must remove `aria-hidden` from the root element
651+
* when the last non-toast overlay is dismissed.
652+
*/
653+
const overlaysNotToast = doc !== undefined ? getPresentedOverlays(doc).filter((o) => o.tagName !== 'ION-TOAST') : [];
654+
655+
const lastOverlayNotToast = overlaysNotToast.length === 1 && overlaysNotToast[0].id === overlay.el.id;
643656

644657
/**
645-
* If this is the last visible overlay then
646-
* we want to re-add the root to the accessibility tree.
658+
* If this is the last visible overlay that is not a toast
659+
* then we want to re-add the root to the accessibility tree.
647660
*/
648-
if (lastOverlay) {
661+
if (lastOverlayNotToast) {
649662
setRootAriaHidden(false);
650663
document.body.classList.remove(BACKDROP_NO_SCROLL);
651664
}

0 commit comments

Comments
 (0)