@holmdigital/components — Toast
Open source React component. Succinct messages that provide temporary feedback on specific actions. Optimized for screen reader announcements.
Toasts are used to confirm actions like "Saved" or "Deleted". Because they disappear, they must be announced immediately via live regions.
Accessibility Features
- Severity-aware role: Error and warning toasts use
role="alert"+aria-live="assertive"; info and success toasts userole="status"+aria-live="polite". Avoids announcing routine confirmations as urgent interruptions (WCAG 4.1.3). - Sticky errors (WCAG 2.2.1 Timing Adjustable): Error toasts default to
Infinityduration — they stay visible until the user dismisses them. Non-error toasts use a reading-rate-aware duration (max(5000ms, content.length * 50ms)). - Pause on hover/focus: The auto-dismiss timer pauses while the toast is hovered or focused, and resumes on leave/blur. Gives users time to read or copy the content.
- Escape-to-dismiss: Pressing Escape from anywhere dismisses the most-recent urgent (error/warning) toast. Routine status toasts are left alone — they're not interruptions the user is asking to clear.
- Per-toast Dismissible: Each toast includes a close button that is keyboard accessible and has a clear
aria-label.
Usage Example
import { useToast } from '@holmdigital/components'; function MyComponent() { const { toast } = useToast(); return ( <button onClick={() => toast({ title: "Success!", description: "Changes saved." })}> Save Changes </button> ); }