Summit
ComponentsFeedback

Toast

A Toast shows users a brief message at the bottom of the screen and disappears by itself.

Summit uses Sonner for toasts. Use this Toast only when a product needs the one built on Base UI.

When Not to Use

  • for a toast in a product (use Sonner, which also has the rules for the content of a toast)
  • for a status that lasts (use an Alert)
  • for a decision before an action (use an Alert Dialog)

See Alert for a comparison of the Alert, the toast, and the Alert Dialog.

SonnerToast
Calltoast('Invoice sent')toast.add({ title: 'Invoice sent' })
Duration4 seconds5 seconds
PositionThe bottom right, or one of five othersThe bottom, at the end edge from 640px
ActionDismisses the toastKeeps the toast open
ShortcutAlt+TF6
EscapeCollapses the stackDismisses the focused toast
Role of a ToastA list itemdialog

Anatomy

ElementUsage
Title*Required
ActionOptional
Close buttonAlways shown
ContainerRequired
DescriptionOptional

* The title is the accessible name of the Toast, which is a dialog.

Toaster renders each Toast from these parts, in this order. The action is shown when the Toast has actionProps. If the Toast has a type, an icon is also shown before the title; the figure doesn’t show it.

Types

type accepts any string. The types success, info, warning, error, and loading show an icon, which is listed under ToastIcon, and any other value shows none. See Sonner for the purpose of each type.

Behavior

Toaster renders the stack in a portal at the end of body, and toast.add adds a Toast to it from anywhere in the app. When a Toast appears, focus doesn’t move, and the page stays interactive.

Duration

By default, a Toast disappears after 5 seconds. To change the duration for all Toasts, set timeout on Toaster. To change it for one Toast, pass timeout to toast.add; if timeout is 0, the Toast doesn’t disappear by itself. A Toast of type loading has no timer. The timers are paused while the pointer or focus is in the stack.

Dismissal

A Toast is dismissed when users click the close button, press Escape while focus is in the Toast, or swipe it to the right or down. A click on the action doesn’t dismiss the Toast, so close the Toast in the action’s onClick.

Stack

By default, the stack shows three Toasts. To change the number, set limit on Toaster. A Toast over the limit is inert and invisible until a place is free. When the pointer or focus is in the stack, the stack expands, and all Toasts are shown in full.

Position and Size

The stack is fixed at the bottom of the screen, at the end edge from 640px. See Layout for its width and Elevation for the order of the layers.

Accessibility

Base UI’s Toast sets the roles, announces each Toast, and moves focus into the stack when users press F6.

The label of the close button is “Close toast” by default. To translate it, use the Summit Provider.

If you pass priority: 'high', the Toast has role="alertdialog", and its title and description are placed in a role="alert" element, which screen readers announce immediately. Pass both as strings.

Requirements

A Toast needs a title so that screen readers can announce its name, as WCAG 2.2 SC 4.1.2 Name, Role, Value requires. The Toast is a dialog, and if it has only a description, it has no name.

DoGive every Toast a title, which is the name of its dialog.
Don’tWhen a Toast has only a description, its dialog has no name, so screen readers have no name to announce.

The two requirements of a toast on Sonner apply to this Toast too. If a Toast must not disappear, pass timeout: 0.

Installation

npx shadcn@latest add @summit/toast

The CLI also adds @summit/button, @summit/summit-provider, and @summit/toast-icon.

Usage

Render Toaster once, around the app, and call toast.add from any event handler.

import { Button } from '@/components/ui/button';
import { toast, Toaster } from '@/components/ui/toast';

<Toaster>
    <Button variant="outline" onClick={() => toast.add({ title: 'Invoice sent' })}>
        Send invoice
    </Button>
</Toaster>;

With an Action

To add an action, pass the props of the action button in actionProps. toast.add returns the id that you pass to toast.close.

With an Action
const id = toast.add({
    title: 'Invoice sent',
    description: 'Atelier Brume will get it by email.',
    actionProps: {
        children: 'Undo',
        onClick: () => {
            unsend(invoice);
            toast.close(id);
        },
    },
});

Follow a Request

To follow a request in one Toast, use toast.promise, which sets the type to loading, and then to success or error. If you pass a string in place of an object, the string becomes the description, and the Toast has no title.

Follow a Request
toast.promise(sendInvoice(invoice), {
    loading: { title: 'Sending the invoice' },
    success: { title: 'Invoice sent' },
    error: { title: 'The invoice was not sent' },
});

Change the Limit and the Timeout

To change the limit and the timeout for all Toasts, set limit and timeout on Toaster.

Change the Limit and the Timeout
<Toaster limit={1} timeout={8000} />

API Reference

The parts accept the props of their matching parts in Base UI’s Toast, where Toast is Toast.Root. See the Base UI Toast documentation for swipeDirection and render.

Toaster

PropTypeDefaultDescription
limitnumber3The number of Toasts shown at once
timeoutnumber5000Milliseconds before a Toast disappears. If it is 0, no Toast disappears by itself.
toastManagerToastManagertoastThe manager whose Toasts the stack shows

createToastManager returns a manager to pass to toastManager. useToastManager is a hook that returns the Toasts and the methods of the manager.

toast

MethodResult
toast.add(options)Shows a Toast and returns its id. If the id exists, that Toast is updated.
toast.update(id, options)Replaces the options that are passed
toast.close(id)Dismisses one Toast, or all Toasts when no id is passed
toast.promise(promise, options)Shows loading, then success or error, and returns the promise

toast.add accepts these options.

OptionTypeDefaultDescription
titleReactNodeNoneThe title, which is the name of the Toast
descriptionReactNodeNoneA line under the title
typestringNoneThe icon, and data-type on the Toast
timeoutnumber5000Milliseconds before the Toast disappears. If it is 0, the Toast doesn’t disappear by itself.
priority'low' | 'high''low'high announces the Toast immediately
actionPropsThe props of a buttonNoneShows the action with these props
idstringGeneratedUpdates the Toast that has this id

See the Base UI Toast documentation for onClose, onRemove, and data.

ToastIcon

ToastIcon is the registry item toast-icon. The CLI installs it with this Toast and with Sonner, and both render it before the title.

TypeIcon
successCheckCircleIcon
infoInfoIcon
warningWarningIcon
errorXCircleIcon
loadingSpinnerIcon

The icon has aria-hidden. For any other type, ToastIcon renders nothing.

PropTypeDefaultDescription
typestring | undefinedRequiredThe type of the toast

On this page