Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/live-region-element/src/global-announce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,20 @@ 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)) {
// If the element exists within a <dialog>, we can only use a live region
// within that element
if (dialog && !dialog.contains(current)) {
break
} else if (ariaModal && !ariaModal.contains(current)) {
break
}

for (const child of current.childNodes) {
Expand All @@ -153,6 +158,11 @@ function getLiveRegionContainer(from?: HTMLElement): HTMLElement {
if (dialog) {
container = dialog
}

const ariaModal = from.closest(ariaModalSelector)
if (ariaModal) {
container = ariaModal
}
}
return container
}
Expand Down
Loading