The Toast component displays temporary notification messages that automatically dismiss after 6 seconds, or after their duration. The countdown pauses while a toast is hovered or has focus. It's typically used through the ToastProvider context, but can also be used standalone.
Toast supports four variants: success for positive feedback, danger for errors, warning for cautionary messages, and info for informational notices.
Add interactive elements like buttons to allow users to take action on the notification.
Hide the default variant icon by setting icon={false}.
The Toaster component manages multiple toast notifications, handling positioning, stacking animations, and portal rendering. It's automatically included when using ToastProvider.
The Toaster:
- Renders toasts in a fixed position at the bottom center of the screen
- Stacks multiple toasts with scale and opacity animations
- Uses React portals to render outside the normal DOM hierarchy
- Limits width to 32rem for optimal readability
Toast components include proper ARIA attributes:
- role="status" with aria-live="polite" for success, info and warning, so the message is announced without interrupting
- role="alert" (assertive) for danger only
- The countdown pauses while the toast holds focus, so there is time to reach its action
- Keyboard-accessible close button with tooltip