SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Announcer

Headless queue of aria-live announcements: a live-region island subscribes to its state and re-renders on change.

tsx
import { Announcer } from "@sdxc/ui/behaviors";

Usage

Owns a priority-ordered queue of aria-live announcements. A live-region island subscribes to "change", renders Announcer.current into an aria-live element, and calls Announcer.next once it has been read.

Signature

typescript
new Announcer(options?: Announcer.Options)

Parameters

ParameterTypeDefaultRequiredDescription
optionsAnnouncer.Options—NoHow long each message holds before the queue advances on its own.

Properties

PropertyTypeDefaultRequiredDescription
currentAnnouncer.Message | undefined—YesThe message a live region should currently render, or undefined when the queue is empty.
messagesreadonly Announcer.Message[]—YesEvery queued message, in the order a live region should announce them.

Methods

MethodDescription
announce(text: string, priority?: Announcer.Priority): stringQueues a message for announcement. Assertive messages are inserted ahead of any polite messages already queued so they interrupt the live region, and behind assertive messages queued earlier; polite messages append.
dismiss(id: string): voidRemoves one queued message by id, wherever it sits in the queue, dispatching "change" only when a message with that id was queued.
next(): voidAdvances past the current message so the next queued one becomes Announcer.current, dispatching "change" only when the queue held a message.
clear(): voidEmpties the queue, dispatching "change" only when it held messages.

Examples

tsx
whileLive(handle, (model: Announcer, signal) => model.addEventListener("change", () => handle.update(), { signal }))(announcer);

The events, constants and types its module publishes, each imported from @sdxc/ui/behaviors too.

Interface

Announcer.Message

One queued announcement.

MemberTypeDefaultRequiredDescription
idreadonly string—YesStable id used to target this message with Announcer.dismiss.
textreadonly string—YesAnnouncement copy, read verbatim by the live region.
priorityreadonly Priority—Yes
Interface

Announcer.Options

Options for constructing an Announcer.

MemberTypeDefaultRequiredDescription
holdnumber—NoMilliseconds each message stays current before the queue advances on its own: long enough for a screen reader to reach it, short enough that a run of quick changes is heard one by one. Omitted, the live region advances the queue with next().
Interface

Announcer.Events

Events dispatched by Announcer.

MemberTypeDefaultRequiredDescription
changeEvent—YesDispatched after a message is queued, dismissed, advanced past, or the queue is cleared.
Type

Announcer.Priority

Politeness a queued message announces with, mirrored onto a live region's aria-live attribute. "assertive" interrupts the current utterance and moves ahead of any "polite" messages already queued.

typescript
type Announcer.Priority = "polite" | "assertive"
@sdxc/ui

Can’t find it? Contact us