Skip to content
Hazine

Undo Toast

Toast that confirms a reversible action and offers Undo, with a thin bar and a seconds count for how long the undo stays open. Use it for archive, delete or move actions that are applied at once.

How it differs. One inline action above a countdown it owns: the bar holds while pointer or focus is in the toast region, commit fires once on expiry or dismissal and never after an undo, which is confirmed in place.

Install

pnpm dlx shadcn@latest add @hazine/toast-undo-action

Adds 1 file, 1 shadcn primitive (button), and 2 packages (sonner, lucide-react).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props14

titlerequired
string
What just happened, in the past tense: "Conversation archived".
description
string
The object the action touched. Clamped to two lines.
icon
React.ReactNode
A 16px lucide icon for the action. Decorative.
duration
number = 8000
Length of the undo window in milliseconds.
defaultRemaining
number
Milliseconds left when the toast mounts. Defaults to `duration`.
paused
boolean = false
Holds the countdown from outside, on top of hover and focus.
undoLabel
string = "Undo"
dismissLabel
string = "Dismiss"
undoneTitle
string = "Action undone"
Replaces the title once the action has been undone.
locale
string = "en-US"
formatHint
(length: string) => string = defaultFormatHint
Screen reader sentence for the window. Receives the localised length, such as "8 seconds".
onUndo
() => void
Undo was pressed. Reverse the action here.
onCommit
(reason: ToastUndoCommitReason) => void
The window closed without an undo, so the action is final. Fires once, when the countdown ends or when the toast is dismissed. Never after an undo.
onClose
() => void
The toast is finished and should be removed from the screen.

Also accepts every prop of Omit<React.ComponentProps<"div">, "title">.

Accessibility

Pattern
Toast with a status region, Button (APG, opens in a new tab)
Keyboard
Keyboard support for Undo Toast
KeyEffect
Alt+TMoves focus to the toast region (the Sonner hotkey). Every countdown holds from then on
TabMoves through the toast, then Undo, then Dismiss. The countdowns hold while keyboard focus is anywhere in the region
Enter or Space on UndoReverses the action, announces the restored title and moves focus to Dismiss
Enter or Space on DismissCloses the toast. Before an undo this also makes the action final. Focus moves to the next toast, or back to where it was when the last one closes
EscapeDismisses the focused toast, with the same result as Dismiss
Screen reader

The message is a status region, kept apart from the buttons so their names are not read as part of it, and it carries a hidden sentence with the length of the window. Undo is described by that message and Dismiss names the title, so stacked toasts can be told apart. The bar and the seconds are hidden from assistive technology. Sonner supplies the Notifications region, and its focused list item is outlined by the toast.

  • Announces: {title} {description} {formatHint}
  • Announces: {undoneTitle} {description}
Reduced motion
The bar and the seconds change once a second instead of every frame. No CSS animation runs in either mode.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies3

  • button
  • sonner
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.

More in Feedback and Status