Sonner

An opinionated toast component for Vue.

About

The Sonner component is provided by vue-sonner, which is a Vue port of Sonner, originally created by Emil Kowalski for React.

Installation

Run the following command

bash
npx shadcn-vue@latest add sonner

Add the Toaster component

Add the following Toaster component to your App.vue file:

vue
<script setup lang="ts">
import { Toaster } from '@/components/ui/sonner'
</script>

<template>
  <Toaster />
</template>

Usage

vue
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { toast } from 'vue-sonner'
</script>

<template>
  <Button
    variant="outline" @click="() => {
      toast('Event has been created', {
        description: 'Sunday, December 03, 2023 at 9:00 AM',
        action: {
          label: 'Undo',
          onClick: () => console.log('Undo'),
        },
      })
    }"
  >
    Add to calendar
  </Button>
</template>

Examples

Sonner with Dialog

Related issue https://github.com/radix-vue/shadcn-vue/issues/462

Add pointer-events-auto class to Toaster component in your App.vue file:

vue
<script setup lang="ts">
import { Toaster } from '@/components/ui/sonner'
</script>

<template>
  <Toaster class="pointer-events-auto" />
</template>
Edit this page on GitHub