Skip to content

Commit

Permalink
fix(overlays): correctly re-add root to accessibility tree
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi committed Sep 15, 2023
1 parent 132173d commit 3da477f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/utils/overlays.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { doc } from '@utils/browser';

import { config } from '../global/config';
import { getIonMode } from '../global/ionic-global';
import type {
Expand Down Expand Up @@ -385,6 +387,17 @@ export const getOverlays = (doc: Document, selector?: string): HTMLIonOverlayEle
return (Array.from(doc.querySelectorAll(selector)) as HTMLIonOverlayElement[]).filter((c) => c.overlayIndex > 0);
};

/**
* Returns a list of all presented overlays.
* Inline overlays can exist in the DOM but not be presented,
* so there are times when we want to exclude those.
* @param doc The document to find the element within.
* @param overlayTag The selector for the overlay, defaults to Ionic overlay components.
*/
const getPresentedOverlays = (doc: Document, overlayTag?: string): HTMLIonOverlayElement[] => {
return getOverlays(doc, overlayTag).filter((o) => !isOverlayHidden(o));
};

/**
* Returns an overlay element
* @param doc The document to find the element within.
Expand All @@ -393,7 +406,7 @@ export const getOverlays = (doc: Document, selector?: string): HTMLIonOverlayEle
* @returns The overlay element or `undefined` if no overlay element is found.
*/
export const getOverlay = (doc: Document, overlayTag?: string, id?: string): HTMLIonOverlayElement | undefined => {
const overlays = getOverlays(doc, overlayTag).filter((o) => !isOverlayHidden(o));
const overlays = getPresentedOverlays(doc, overlayTag);
return id === undefined ? overlays[overlays.length - 1] : overlays.find((o) => o.id === id);
};

Expand Down Expand Up @@ -525,7 +538,13 @@ export const dismiss = async <OverlayDismissOptions>(
return false;
}

setRootAriaHidden(false);
/**
* If this is the last visible overlay then
* we want to re-add the root to the accessibility tree.
*/
if (doc !== undefined && getPresentedOverlays(doc).length === 1) {
setRootAriaHidden(false);
}

overlay.presented = false;

Expand Down

0 comments on commit 3da477f

Please sign in to comment.