Toast
Shows a toast message in the corner. You need to have a <Toaster /> component on your page.
Toasts share their types and icons with Alert: info (the default), success, warning and error. The accent shows up in the icon, the border and a faint surface tint, so an error reads as an error without shouting.
Examples
Basic toast
Code
vue
<template>
<Button
@click="toast({ title: 'Heads up', description: 'Your export will be ready in a moment.' })"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { useToast } from '@/components/ui/toast'
const { toast } = useToast()
</script>Success toast
Code
vue
<template>
<Button
@click="toast({ type: 'success', title: 'Saved', description: 'Item successfully added!' })"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { useToast } from '@/components/ui/toast'
const { toast } = useToast()
</script>Warning toast
Code
vue
<template>
<Button
@click="toast({ type: 'warning', title: 'Almost out of space', description: 'You have used 90% of your quota.' })"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { useToast } from '@/components/ui/toast'
const { toast } = useToast()
</script>Error toast
Code
vue
<template>
<Button
@click="toast({ type: 'error', title: 'Something went wrong', description: 'The item could not be added.' })"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { useToast } from '@/components/ui/toast'
const { toast } = useToast()
</script>Toast without icon
Code
vue
<template>
<Button
@click="toast({ removeIcon: true, description: 'Copied to clipboard.' })"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { useToast } from '@/components/ui/toast'
const { toast } = useToast()
</script>Toast with an action
Code
vue
<template>
<Button
@click="toast({
title: 'In progress...',
description: 'Your export is being processed.',
action: h(ToastAction, {
altText: 'Undo',
onClick () {
dismiss()
}
}, {
default: () => 'Undo',
})
})"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { ToastAction, useToast } from '@/components/ui/toast'
import { h } from 'vue'
const { toast, dismiss } = useToast()
</script>Non-dismissible toast
Two separate things keep a toast on screen, and they are opt-in:
dismissible: falseremoves the close button and blocks swipe and Escape, so the user cannot dismiss it.duration: Infinitystops it auto-closing, so it waits instead of timing out. Useful on its own for a toast whose action needs time to be acted on.
Use dismissible: false only when the action itself resolves the toast — combined with duration: Infinity there is otherwise no way out of it.
Code
vue
<template>
<Button
@click="toast({
type: 'warning',
dismissible: false,
duration: Infinity,
title: 'Your session expired',
description: 'Reload the page to keep working.',
action: h(ToastAction, {
altText: 'Reload',
onClick () {
dismiss()
}
}, {
default: () => 'Reload',
})
})"
>
Show toast
</Button>
</template>
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { ToastAction, useToast } from '@/components/ui/toast'
import { h } from 'vue'
const { toast, dismiss } = useToast()
</script>