LiveRegion
FeedbackAccessible status announcements with a hook for repeated messages.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import {
LiveRegion,
useAnnouncer,
} from "@dashboardpack/core/components/ui/live-region";
import { Button } from "@dashboardpack/core/components/ui/button";
export default function LiveRegionExample() {
const { message, announce } = useAnnouncer();
return (
<div className="space-y-4">
<Button onClick={() => announce("Your changes have been saved.")}>
Announce saved changes
</Button>
<LiveRegion visible className="min-h-6 text-sm text-muted-foreground">
{message}
</LiveRegion>
<p className="text-xs text-muted-foreground">
The status region is mounted before its message changes. Click again to
repeat the announcement.
</p>
</div>
);
}Usage
Mount a LiveRegion before changing its message. useAnnouncer returns message, announce, and clear; it makes repeated identical announcements detectable.
import {
LiveRegion,
useAnnouncer,
} from "@dashboardpack/core/components/ui/live-region";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| politeness | polite | assertiveDefault: polite | Announcement priority and status/alert role. |
| atomic | booleanDefault: true | Announce the whole message after changes. |
| visible | booleanDefault: false | Render visible text instead of screen-reader-only content. |
| children | ReactNodeDefault: — | Current status message. |