Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Toast for React

Provides feedback on an action.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/base/toast.json

Anatomy

ToastItem
├── ToastGroup
├── ToastTitle
├── ToastDescription
├── ToastActionTrigger
└── ToastCloseTrigger

Usage

import { Button } from "@/components/ui/button";
import { createToaster, Toaster } from "@/components/ui/toast";
const toast = createToaster({
  overlap: true,
  placement: "bottom-end",
});

const ToastDemo = () => {
  const handleShowToast = () => {
    const id = toast.create({
      action: {
        label: "Undo",
        onClick() {
          toast.dismiss(id);
        },
      },
      description: "Sunday, December 3 at 9:00 AM",
      title: "Event created",
    });
  };

  return (
    <>
      <Toaster toaster={toast} />
      <Button onClick={handleShowToast} variant="outline">
        Show Toast
      </Button>
    </>
  );
};

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.

Demos

Types

Set the type option to render a status icon.

Promise

Use toast.promise for loading, success, and error states.

API Reference

Toast

div

PropType
AttributeType
CSS variableType
--gapstring
--heightstring
--offset-ystring
--peekstring
--scalestring
--shrinkstring
--toast-heightstring
--toast-indexstring
--toast-offset-ystring
--toast-swipe-movement-xstring
--toast-swipe-movement-ystring

ToastItem

div

PropType
className?string
AttributeType

ToastTitle

h2

PropType
AttributeType

ToastDescription

p

PropType
AttributeType

toast

PropType
AttributeType

ToastPortal

div

PropType
AttributeType

ToastViewport

div

PropType
AttributeType

ToastContent

div

PropType
AttributeType

ToastAction

button

PropType
AttributeType

ToastClose

button

PropType
AttributeType

ToastActionTrigger

PropType
AttributeType

ToastCloseTrigger

PropType
AttributeType

ToastIcon

PropType
className?string
AttributeType

Toaster

PropType
AttributeType

ToastProvider

PropType
children?React.ReactNode
AttributeType

useToast