shadcn.io is not affiliated with official shadcn/ui
Sonner examples · Interactive
Toast with Cancel Button Sonner for React
A toast with a Cancel button that closes it and shows an info toast.
A cancel button gives a toast a clear way to say no. This toast passes cancel with a label and an onClick; clicking Cancel closes it and shows an info toast.
Preview
Installation
FAQ
How is the Cancel button set?
The title is "Are you sure you want to continue?". cancel is { label: "Cancel", onClick: () => toast.info("Action cancelled") }. The label is the button text.
What happens when Cancel is clicked?
onClick runs and the toast closes. dismissible is not set, so the button is active. An info toast then shows "Action cancelled".
How do I add a confirm button next to it?
Pass action with a label and an onClick. This file passes cancel only, so there is one button.
Does a swipe do the same thing as Cancel?
A swipe closes the toast and does not run onClick. Cancel runs toast.info and then closes. This call does not pass dismissible.
Related
- Toast with Action Button SonnerA toast with an Undo action button that
- Toast with Action and Cancel SonnerA toast with a Delete action and a Cancel
- Non-Dismissible Toast SonnerA toast that can't be swiped away and
- Default Toast SonnerA button that shows a plain toast with
- Toast with Custom Duration SonnerA toast that stays on screen for 10
- Toast with Custom Icon SonnerA toast with its own check icon in place