Feedback
Toast
Brief, non-blocking notifications about something that just happened. Each ToastProvider owns its queue, so micro-frontends never share global state.
import { ToastProvider, useToast } from '@reactloom/ui';Examples
Tones
Danger toasts are announced assertively and stay until dismissed.
import { Button, HStack, ToastProvider, useToast } from '@reactloom/ui';
function Actions() {
const toast = useToast();
return (
<HStack gap="2" wrap>
<Button onClick={() => toast.show({ title: 'Changes saved', tone: 'success' })}>Save</Button>
<Button
variant="secondary"
onClick={() => toast.show({ title: 'Storage almost full', description: '92% of 10 GB used.', tone: 'warning' })}
>
Warn
</Button>
<Button
variant="destructive"
onClick={() => toast.show({ title: 'Upload failed', description: 'The file is larger than 25 MB.', tone: 'danger' })}
>
Fail
</Button>
</HStack>
);
}
export default function Example() {
// Usually one provider near the root of your app (or of each micro-frontend).
return (
<ToastProvider>
<Actions />
</ToastProvider>
);
}With an action
Toasts with an action never time out, so everyone has time to use it.
Archived: 0
import { Button, Text, ToastProvider, useToast } from '@reactloom/ui';
import { useState } from 'react';
function Inbox() {
const toast = useToast();
const [archived, setArchived] = useState(0);
return (
<>
<Button
onClick={() => {
setArchived((n) => n + 1);
toast.show({
id: 'archive',
title: 'Conversation archived',
action: { label: 'Undo', onAction: () => setArchived((n) => n - 1) },
});
}}
>
Archive conversation
</Button>
<Text size="sm" tone="muted">Archived: {archived}</Text>
</>
);
}
export default function Example() {
return (
<ToastProvider>
<Inbox />
</ToastProvider>
);
}Updating a toast
Show again with the same id to replace it.
import { Button, ToastProvider, useToast } from '@reactloom/ui';
function Publish() {
const toast = useToast();
return (
<Button
onClick={() => {
// Reusing an id replaces the toast in place and announces the new text.
toast.show({ id: 'publish', title: 'Publishing…', duration: Infinity });
setTimeout(() => toast.show({ id: 'publish', title: 'Published', tone: 'success' }), 1200);
}}
>
Publish
</Button>
);
}
export default function Example() {
return (
<ToastProvider placement="top-center">
<Publish />
</ToastProvider>
);
}API reference
ToastProvider props
| Prop | Type | Default |
|---|---|---|
placement | 'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end' | 'bottom-end' |
maxShown at once; later toasts wait in order. | number | 3 |
durationDefault auto-dismiss delay in ms. | number | 6000 |
labelName of the landmark. | string | 'Notifications' |
dismissLabelTranslate this. | string | 'Dismiss' |
hotkeyMoves focus to the notifications. | string | null | 'F8' |
useToast() → show(options)
| Prop | Type | Default |
|---|---|---|
titlerequired | ReactNode | — |
description | ReactNode | — |
tone | 'neutral' | 'info' | 'success' | 'warning' | 'danger' | 'neutral' |
actionOne action; the toast then stays until dismissed. | { label, onAction } | — |
durationInfinity keeps it. Danger and action toasts default to Infinity. | number | — |
idReuse to replace a toast. | string | — |
onDismiss | () => void | — |
→ returnsThe id, for dismiss(id). Also: dismissAll(). | string | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-placement] | top-start · top-center · top-end · bottom-start · bottom-center · bottom-end |
Accessibility
- Text is announced through live regions that exist before any toast appears — the reliable way to get screen readers to speak dynamic content.
- The stack is a labelled region landmark; F8 moves focus to it and Escape dismisses the focused toast, returning focus where you were.
- Timers pause while the pointer is over the stack, while focus is inside it, and while the tab is hidden (WCAG 2.2.1).
- Toasts render in the top layer but inside your DOM tree, so scoped themes apply. While a modal dialog is open, everything outside it is inert — show feedback inside the dialog instead.
| Key | Action |
|---|---|
| F8 | Move focus to the notifications |
| Tab | Move between toast actions |
| Escape | Dismiss the focused toast |
Usage guidelines
Do
- Use for confirmations and background events (“Saved”, “Upload complete”).
- Offer Undo instead of a confirmation dialog for reversible actions.
Don’t
- Don’t put the only copy of critical information in a toast — use Alert or a Dialog.
- Don’t use toasts for form validation errors — show them next to the field.