Skip to Content
zjkm-ui
Components

Undo Toast

A toast with an Undo button.

Props
<UndoToast open={open} message="Message deleted" onUndo={restore} onClose={close} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/undo-toast.json
import { UndoToast } from "@/components/undo-toast"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

"Message deleted · Undo". It times out on its own, and hovering or focusing it pauses the timer, so there's time to reach the button. It sits fixed in the bottom-right corner of the window and announces itself politely to screen readers.

import { UndoToast } from "@/components/undo-toast";

export function Inbox() {
  const [deleted, setDeleted] = useState<Message | null>(null);
  return (
    <UndoToast
      open={!!deleted}
      message="Message deleted"
      onUndo={() => restore(deleted!)}
      onClose={() => setDeleted(null)}
    />
  );
}

Props

PropTypeDefaultDescription
openbooleanShows the toast.
messagestringWhat happened.
onUndo() => voidCalled when Undo is pressed.
onClose() => voidCalled when it times out, is dismissed, or after Undo.
durationnumber5000Milliseconds before it times out.

With reduced motion, it appears without sliding in.

On this page