DisplayReact
A way to have screen readers speak a message after something happens that the page shows only by sight: an item added to a list, a save that finished, an error.
Rendered by React 19.3.1
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<LiveAnnouncer />Examples
Dialog
A native dialog opened with showModal() that holds its own LiveAnnouncer; its "Save draft" button announces "Draft saved" into it.
API reference
0 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.
LiveAnnouncerLiveAnnouncer
A visually hidden element holding a polite and an assertive live region, which announce() writes its messages into. Renders a <div>.
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
LiveAnnouncer takes no focus and has no keys. The buttons in the examples are plain buttons: Enter and Space press them.
Accessibility
| Part | Sets | So that |
|---|---|---|
| LiveAnnouncer | the hidden style; no role or ARIA on its element; on its two regions role, aria-live and aria-atomic (see above) | a message written into a region is read by the screen reader without a focus move |
Focus order
- LiveAnnouncer is not focusable; focus passes over it.
announcenever moves the focus.