Overlay
Toast
Stacked, swipeable notifications. Exports a global toast manager plus a <Toaster /> to mount once.
Show codeHide code
"use client";
import { Button } from "@/registry/lilt/ui/button";
import { toast, Toaster } from "@/registry/lilt/ui/toast";
export default function ToastDemo() {
return (
<>
<Toaster />
<div className="flex flex-wrap items-center justify-center gap-3">
<Button
onClick={() =>
toast.add({
description: "Your changes synced a moment ago.",
title: "Nice. Everything is up to date.",
})
}
variant="soft"
>
Show a toast
</Button>
<Button
onClick={() =>
toast.promise(
// oxlint-disable-next-line promise/avoid-new -- wraps the timer-based setTimeout API, no async alternative exists
new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 1600);
}),
{
error: { title: "Publishing failed. Try again." },
loading: { title: "Publishing…" },
success: { title: "Published. Go take a walk." },
}
)
}
variant="secondary"
>
Promise toast
</Button>
</div>
</>
);
}Installation
npx shadcn@latest add @lilt/toastAccessibility
- Toasts are announced politely by screen readers and pause on hover or focus.
- F6 moves focus into the toast viewport; swipe or the close button dismisses.