diff --git a/packages/live-region-element/src/global-announce.ts b/packages/live-region-element/src/global-announce.ts index cb122f0..705186b 100644 --- a/packages/live-region-element/src/global-announce.ts +++ b/packages/live-region-element/src/global-announce.ts @@ -123,8 +123,11 @@ function findLiveRegion(from?: HTMLElement): LiveRegionElement | null { return null } +const ariaModalSelector = '[aria-modal="true"][role="dialog"],[aria-modal="true"][role="alertdialog"]' + function getClosestLiveRegion(from: HTMLElement): LiveRegionElement | null { const dialog = from.closest('dialog') + const ariaModal = from.closest(ariaModalSelector) let current: HTMLElement | null = from while ((current = current.parentElement)) { @@ -132,6 +135,8 @@ function getClosestLiveRegion(from: HTMLElement): LiveRegionElement | null { // within that element if (dialog && !dialog.contains(current)) { break + } else if (ariaModal && !ariaModal.contains(current)) { + break } for (const child of current.childNodes) { @@ -153,6 +158,11 @@ function getLiveRegionContainer(from?: HTMLElement): HTMLElement { if (dialog) { container = dialog } + + const ariaModal = from.closest(ariaModalSelector) + if (ariaModal) { + container = ariaModal + } } return container }