-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototype aria-live for interactive graphs
- Loading branch information
1 parent
b055724
commit c4bbbcb
Showing
4 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/perseus/src/widgets/interactive-graphs/ariaLiveAnnounce.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
type PolitenessLevel = "assertive" | "polite"; | ||
|
||
export function ariaLiveAnnounce(message: string, options?: {level?: PolitenessLevel}): void { | ||
const region = recreateAriaLiveRegion(options?.level ?? "polite") | ||
region.innerText = message | ||
} | ||
|
||
let currentAriaLiveRegion: HTMLDivElement | null = null | ||
function recreateAriaLiveRegion(politenessLevel: PolitenessLevel): HTMLDivElement { | ||
if (currentAriaLiveRegion) { | ||
document.body.removeChild(currentAriaLiveRegion) | ||
} | ||
|
||
currentAriaLiveRegion = createAriaLiveRegion(politenessLevel) | ||
return currentAriaLiveRegion | ||
} | ||
|
||
function createAriaLiveRegion(politenessLevel: PolitenessLevel): HTMLDivElement { | ||
console.log("createAriaLiveRegion") | ||
const newRegion = document.createElement("div") | ||
newRegion.setAttribute("aria-live", politenessLevel) | ||
newRegion.classList.add("perseus-aria-live-region") | ||
return document.body.appendChild(newRegion) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters