Skip to content

Alert

  • A warning or notice about the page or account: “Your trial ends in 3 days”
  • A summary of form errors at the top of a form
  • The result of an action that must stay visible until it is dealt with

Not for a brief confirmation that can go away by itself — use a Toast.

Choosing between messages and popups:

ComponentUse it forFor example
DialogSomething that needs a decision or input before the user carries on; the page is blocked meanwhileConfirm a delete, edit a record in a form
DrawerA panel that slides in from an edge and blocks the page; the first choice on a phoneShare options, a mobile nav, a filter panel
PopoverExtra content or controls next to a button, while the rest of the page stays usableFilter panel, share options, details card
MenuA list of actions or settings opened from a button“More actions ⋯”, a View menu
TooltipA short text label on hover or focus; nothing in it can be clickedName of an icon button, a keyboard shortcut
HoverCardA preview of where a link goes, on hover or focus; nothing essential in itA profile behind an @mention, a repository’s summary
ToastA brief confirmation after an action, which goes away by itself“Saved”, “Archived — Undo”
AlertA message that stays in the page until the situation changes“Your trial ends in 3 days”, a form error summary

Scheduled maintenance

Sunday 02:00–03:00 UTC.

New in 4.16

Field, Link and Slider landed.

Saved

Your changes are live.

Storage almost full

You have used 92% of your plan.

Payment failed

Check the card details and try again.
import { Alert } from '@arun-dev/ui';
const icon = (
<svg
viewBox="0 0 16 16"
width="16"
height="16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
>
<circle cx="8" cy="8" r="6.5" />
<path d="M8 7v4M8 5h.01" strokeLinecap="round" />
</svg>
);
const tones = [
{ tone: 'neutral', title: 'Scheduled maintenance', text: 'Sunday 02:00–03:00 UTC.' },
{ tone: 'info', title: 'New in 4.16', text: 'Field, Link and Slider landed.' },
{ tone: 'success', title: 'Saved', text: 'Your changes are live.' },
{ tone: 'warning', title: 'Storage almost full', text: 'You have used 92% of your plan.' },
{ tone: 'error', title: 'Payment failed', text: 'Check the card details and try again.' },
] as const;
export default function AlertTones() {
return (
<div
style={{
display: 'grid',
gap: 'var(--space-sm)',
inlineSize: '28rem',
maxInlineSize: '100%',
}}
>
{tones.map(({ tone, title, text }) => (
<Alert.Root key={tone} tone={tone} icon={icon}>
<Alert.Title>{title}</Alert.Title>
<Alert.Description>{text}</Alert.Description>
</Alert.Root>
))}
</div>
);
}

Alert is a message box with a tone, an optional icon, a title and a description.

An alert that is on the page from the start is just content, so it has no live role by default. When it appears in response to something, add one so screen readers read it out:

  • role="alert": urgent, read out at once. A failed save, a lost connection.
  • role="status": polite, read out when the user is idle. “Saved”, “3 results”.
{
error && (
<Alert.Root tone="error" role="alert">
<Alert.Title>Save failed</Alert.Title>
</Alert.Root>
);
}

For a brief message that goes away on its own, use a Toast.

Alert.Root props
PropTypeDefaultDescription
tone'neutral' | 'info' | 'success' | 'warning' | 'error''neutral'Colour, on the status tokens.
iconReactNodeAn icon before the text. Decorative: hidden from assistive technology.
classNamestringConcatenated with the component's own classes, never replacing them.
renderReactElementElement or component to render instead of the default. Props, className, event handlers and ref are merged onto it.
refRef<HTMLElement>Ref to the rendered element. Merged with any ref on the render element.
…restHTMLAttributesAnything else is spread onto the rendered element, so id, aria-*, data-* and event handlers all reach the DOM.

Alert.Title renders a <p> (pass render={<h2 />} if it heads a section), and Alert.Description a <div>.

  • Tones map onto the --color-status-* tokens, as Badge’s do. Override --alert-error-bg and the other tone tokens to restyle one tone.