Skip to content

Migrate from Sonner

import { toast, Toaster } from 'sonner';
import { toast, Toaster } from 'scrollsheet';
import 'scrollsheet/toast.css';

The toast, useSonner, and Toaster exports use a persistent card per toast, portaled through one shared <section> in document.body, or in the topmost modal <dialog> while one is open, and positioned with CSS.

The methods (toast(), .success(), .error(), .info(), .warning(), .loading(), .message(), .custom(render), .promise(), .dismiss(id?)) work before or after a <Toaster> mounts, backed by one shared module-level queue.

Add several toasts to see the stack, newest on top.

Behavior Detail
Repeated id Updates that toast in place instead of stacking a duplicate
toasterId A toast() call with a matching toasterId shows only on that instance, the one rendered as <Toaster id="...">; everything else lands on the default un-keyed one. <Toaster toasterId> still works but is deprecated
position All six Sonner positions render; a toast’s own position overrides the Toaster’s default for just that one toast
Stack Each toast keeps its card. The stack expands on hover or Alt+T (configurable via hotkey). Escape dismisses the front toast, or collapses the stack back if the hotkey opened it, though a stack the pointer is still hovering stays expanded until the pointer leaves
visibleToasts Caps how many toasts show at once, default 3. Extra toasts stay mounted and hidden with their timers running. They fade in when a slot opens. Minimum 1: 0 or negative still shows one
Auto-dismiss Uses the toast’s own duration, or the Toaster’s. Pauses on hover, any pointer down on the stack (including mid-swipe), keyboard expand, and a hidden tab, resuming with the time left rather than a fresh countdown; updating a live toast’s duration re-arms the timer from the new value
Action / cancel buttons Cancel runs its handler and dismisses only when the toast is dismissible; action always runs its handler and dismisses unless it calls event.preventDefault()
classNames.default Applies to neutral toasts, alongside classNames.toast; per-type classes apply to their matching toast type
type: 'loading' Can’t be swiped or closed by button, regardless of dismissible
toast.promise() Accepts an extended result object ({ message, ...rest }) from success/error; a static description set at call time survives to the settled toast
toast.getToasts() / .getHistory() Mirror Sonner’s own introspection API; history is capped at 100 entries
testId, closeButtonAriaLabel Render as data-testid; override the close button’s accessible name
Per-toast style toast('Saved', { style: { top: '8px' } }) puts inline styles on that toast’s row, merged over the stack’s own offset and scale variables, so position and zIndex overrides stick. toastOptions.style on the Toaster sets the base for every row

Swipe-to-dismiss tracks both axes: drag past 45px or flick it fast enough and it dismisses, release short of that and it springs back. Enter/exit, the stack’s expand/collapse, and the swipe itself are all CSS transitions, not a JS animation loop; prefers-reduced-motion: reduce disables these transitions.

Sonner injects its styles automatically; scrollsheet’s default entry expects scrollsheet/toast.css. Add scrollsheet/styles.css too if the app uses sheets or dialogs.

To inject styles on first render, import toast and Toaster from scrollsheet/auto. Also use this entry if your CSS pipeline compiles away custom properties, such as with postcss-css-variables. The layout needs those variables at runtime.