5 Toaster
L4stIdi0t edited this page 2026-11-17 17:40:23 +01:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Toaster

Melt/sonner-style toaster: toasts collapse into a peeking stack at the bottom-right and fan out on hover/focus.

Countdowns pause while hovered or focused, and Escape dismisses the focused toast. Portalled to the body and flagged data-driftwood-live, so a Dialog's inert background leaves it alone — a toast raised over a modal stays announced and dismissable. Announcing: an error toast is a role="alert", which every screen reader speaks the moment it is inserted. Any other toast is spoken through a polite live region that is always in the page — a role="status" that arrives together with its text is not reliably announced, and the old polite list around an alert read errors out twice. The spoken copy is removed again after a moment, so browsing the page does not meet each toast twice.

Feedback · portalled to <body> · keyboard contract

<script lang="ts">
	import { Toaster } from '@l4st/driftwood';
</script>
Light Dark
toaster toaster in dark mode

Props

Prop Type Default What it does
label string 'Notifications' Names the region the toasts live in.
dismissLabel string 'Dismiss notification' Names each toast's dismiss button.
classes Classes<ToasterPart> — Classes for the parts inside: viewport (the list the toasts stack in), item (each toast's place in the stack), toast, icon, body (the title and description), title, description, close (the × button), closeIcon. Merged last, so they win; each toast carries data-type (default, success or error) to style it.

Keyboard

Key Does
Escape dismiss the focused toast

Example

The markup behind the screenshot above, lifted from src/routes/shots/ — so it compiles, and it is exactly what produced the image.

<script lang="ts">
	import { Toaster, toast } from '$lib/index.js';
	import { onMount } from 'svelte';

	onMount(() => {
		toast.success({ title: 'Scan complete', description: '2.56M files indexed.', duration: 0 });
		toast.error({ title: 'Scan failed', description: 'Permission denied on /mnt/cold.', duration: 0 });
		toast({ title: 'Settings saved', duration: 0 });
	});
</script>

<Toaster />

Feedback · Badge · Alert · Progress · Spinner · Skeleton · Avatar · Image


← All components · Getting started · Theming · source