Skip to main content

Toast

Toast notifications provide brief, non-intrusive feedback about an operation. They appear temporarily and can include actions.

import { Toast } from "@ninna-ui/feedback"
pnpm add @ninna-ui/feedback

Requires @ninna-ui/core (auto-installed) + CSS setup.

View source

Usage

Add the Toaster component to your app root, then use the toast function to show notifications.

import { Toaster, toast } from "@ninna-ui/feedback";
// Add Toaster to your app root
export default function App() {
return (
<>
<YourApp />
<Toaster />
</>
);
}
// Use toast anywhere in your app
function MyComponent() {
return (
<button onClick={() => toast.create({ title: "Saved!", color: "success" })}>
Save
</button>
);
}

Basic

Basic toast notification with title and description.

Colors

Different toast colors for various notification purposes.

Variants

Visual variants for different styles.

Positions

Each Toaster instance has its own position. Use id on Toaster and toasterId on toast.create() to route toasts to specific positions independently.

With Action

Toast with an action button.

Custom Duration

Control how long toasts stay visible.

Promise

Show loading, success, or error states based on a promise.

Simple Messages

Quick toast with just a string message.

Dismiss

Programmatically dismiss toasts.

API Reference

Complete API documentation for Toast components.

Toaster Props

PropTypeDefaultDescription
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Position of toasts on screen
idstring-Unique identifier - only toasts created with a matching toasterId will be shown by this Toaster. Omit for the default global Toaster.
maxnumber5Maximum number of visible toasts
gapnumber8Gap between toasts in pixels
offsetstring | number'1rem'Offset from screen edges
pauseOnHoverbooleantruePause auto-dismiss when hovering over toasts
classNamestring-Additional CSS classes for the toast container

Toast Options

PropTypeDefaultDescription
titleReactNode-Toast title
descriptionReactNode-Toast description/message
color'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'danger' | 'warning' | 'info''primary'Color theme of the toast
isLoadingbooleanfalseShow a spinning loader icon. Use with duration: 0 to keep the toast persistent until updated.
variant'solid' | 'soft' | 'outline''soft'Visual variant
durationnumber5000Duration in milliseconds (0 = persistent)
closablebooleantrueWhether the toast can be dismissed
iconReactNode-Custom icon
action{ label: string; onClick: () => void; altText?: string }-Action button configuration
toasterIdstring-Route this toast to a specific Toaster by its id. Omit to send to the default global Toaster.

Toast Methods

PropTypeDefaultDescription
toast.create(options)string-Create a new toast. Pass color to indicate type (e.g. success, danger). Returns the toast ID.
toast.dismiss(id?)void-Dismiss a specific toast by ID, or dismiss all toasts if no ID is provided
toast.dismissAll()void-Dismiss all toasts
toast.update(id, options)void-Update an existing toast by ID
toast.promise(promise, options)Promise<T>-Show a loading toast while the promise is pending, then update to success or danger on resolution

Accessibility

ARIA Support

  • role="status": Used for non-critical toasts (neutral, primary, secondary, accent, success, info, warning)
  • role="alert": Used for error toasts (danger) to ensure immediate announcement
  • aria-live="polite": Default for non-critical notifications
  • aria-live="assertive": Automatically set for error notifications
  • aria-atomic="true": Ensures the entire toast is announced

Keyboard Navigation

  • Escape: Dismisses the most recent toast
  • Tab: Navigate between toast elements (action button, close button)
  • Enter/Space: Activate focused button

Focus Management

  • Toasts are focusable with tabIndex=0
  • Focus is not stolen when toasts appear
  • Close buttons have proper aria-label
  • Action buttons include aria-label with altText

Motion & Timing

  • prefers-reduced-motion: Animations are disabled for users who prefer reduced motion
  • Pause on hover: Auto-dismiss pauses when hovering over toasts
  • Pause on focus: Auto-dismiss pauses when toast is focused