Repository navigation
feat: support aria-busy state announcement #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ type ValueOf<T> = T[keyof T]; | |
| * Live region attributes: | ||
| * | ||
| * - aria-atomic | ||
| * - TODO: aria-busy | ||
| * - aria-busy | ||
| * - aria-live | ||
| * - aria-relevant | ||
| * | ||
|
|
@@ -53,6 +53,7 @@ const RELEVANT = { | |
|
|
||
| const RELEVANT_VALUES = new Set(Object.values(RELEVANT)); | ||
| const DEFAULT_ATOMIC = false; | ||
| const DEFAULT_BUSY = false; | ||
| const DEFAULT_LIVE = LIVE.OFF; | ||
| const DEFAULT_RELEVANT = [RELEVANT.ADDITIONS, RELEVANT.TEXT]; | ||
|
|
||
|
|
@@ -185,17 +186,20 @@ function getLiveRegionAttributes( | |
| }, | ||
| { | ||
| atomic, | ||
| busy, | ||
| live, | ||
| liveTarget, | ||
| relevant, | ||
| }: { | ||
| atomic?: boolean; | ||
| busy?: boolean; | ||
| live?: ValueOf<typeof LIVE>; | ||
| liveTarget?: Element; | ||
| relevant?: ValueOf<typeof RELEVANT>[]; | ||
| } = {} | ||
| ): { | ||
| atomic: boolean; | ||
| busy: boolean; | ||
| live: ValueOf<typeof LIVE>; | ||
| liveTarget?: Element; | ||
| relevant: ValueOf<typeof RELEVANT>[]; | ||
|
|
@@ -218,6 +222,10 @@ function getLiveRegionAttributes( | |
| atomic = target.getAttribute("aria-atomic") === "true"; | ||
| } | ||
|
|
||
| if (typeof busy === "undefined" && target.hasAttribute("aria-busy")) { | ||
| busy = target.getAttribute("aria-busy") === "true"; | ||
| } | ||
|
|
||
| if (typeof live === "undefined" && target.hasAttribute("aria-live")) { | ||
| live = target.getAttribute("aria-live") as ValueOf<typeof LIVE>; | ||
| liveTarget = target; | ||
|
|
@@ -250,11 +258,13 @@ function getLiveRegionAttributes( | |
|
|
||
| if ( | ||
| typeof atomic !== "undefined" && | ||
| typeof busy !== "undefined" && | ||
| typeof live !== "undefined" && | ||
| typeof relevant !== "undefined" | ||
| ) { | ||
| return { | ||
| atomic, | ||
| busy, | ||
| live, | ||
| liveTarget, | ||
| relevant, | ||
|
|
@@ -266,6 +276,7 @@ function getLiveRegionAttributes( | |
| if (target === container || targetAncestor === null) { | ||
| return { | ||
| atomic: atomic ?? DEFAULT_ATOMIC, | ||
| busy: busy ?? DEFAULT_BUSY, | ||
| live: live ?? DEFAULT_LIVE, | ||
| liveTarget, | ||
| relevant: relevant ?? DEFAULT_RELEVANT, | ||
|
|
@@ -276,6 +287,7 @@ function getLiveRegionAttributes( | |
| { container, target: targetAncestor }, | ||
| { | ||
| atomic, | ||
| busy, | ||
| live, | ||
| liveTarget, | ||
| relevant, | ||
|
|
@@ -285,20 +297,65 @@ function getLiveRegionAttributes( | |
|
|
||
| export function getLiveSpokenPhrase({ | ||
| container, | ||
| mutation: { addedNodes, removedNodes, target, type }, | ||
| mutation, | ||
| mutations, | ||
| }: { | ||
| container: Node | null; | ||
| mutation: MutationRecord; | ||
| mutations: MutationRecord[]; | ||
| }): string { | ||
| const { atomic, live, liveTarget, relevant } = getLiveRegionAttributes({ | ||
| const { addedNodes, attributeName, removedNodes, target, type } = mutation; | ||
| const targetElement = getElementFromNode(target); | ||
| const { atomic, busy, live, liveTarget, relevant } = getLiveRegionAttributes({ | ||
| container, | ||
| target: getElementFromNode(target), | ||
| target: targetElement, | ||
| }); | ||
|
|
||
| if (live === LIVE.OFF || !liveTarget) { | ||
| return ""; | ||
| } | ||
|
|
||
| if (type === "attributes" && attributeName === "aria-busy") { | ||
| const isLastAriaBusyMutationForTarget = | ||
| mutations | ||
| .filter( | ||
| (m) => | ||
| m.type === "attributes" && | ||
| m.attributeName === "aria-busy" && | ||
| isElement(m.target) && | ||
| liveTarget.contains(m.target) | ||
| ) | ||
| .at(-1) === mutation; | ||
|
|
||
| if (!isLastAriaBusyMutationForTarget) { | ||
| return ""; | ||
| } | ||
|
|
||
| if (liveTarget.getAttribute("aria-busy") === "true") { | ||
| return ""; | ||
| } | ||
|
|
||
| const liveContent = getSpokenPhraseForNode(liveTarget); | ||
|
|
||
| if (!liveContent) { | ||
| return ""; | ||
| } | ||
|
|
||
| return `${live}: ${liveContent}`; | ||
|
Comment on lines
+338
to
+344
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer to fall-through to the existing logic in this instance - this neglects to utilise the existing aria-atomic and aria-relevant logic. I.e. this |
||
| } | ||
|
|
||
| const hasAriaBusyChangeInBatch = mutations.some( | ||
| (m) => | ||
| m.type === "attributes" && | ||
| m.attributeName === "aria-busy" && | ||
| isElement(m.target) && | ||
| liveTarget.contains(m.target) | ||
| ); | ||
|
Comment on lines
+347
to
+353
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand what this is for? Any mutation in the batch that changes |
||
|
|
||
| if (hasAriaBusyChangeInBatch || busy) { | ||
| return ""; | ||
| } | ||
|
|
||
| /** | ||
| * TODO: Indicates whether assistive technologies will present all, or only | ||
| * parts of, the changed region based on the change notifications defined by | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work to simply check
busyhere? That would cover if the live target is busy, but also if it is nested in an ancestor that is busy (which feels more complete?).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider even hoisting this out of the
ifto live at theLIVE.OFFlevel as there is no need to consider mutations etc. if we know the element / ancestor is busy.