Alert
A message that stays on the page until the situation it describes changes.
When to use
- A message about the state of the page that stays until the situation changes: an expiring API key, a failed sync.
- A form-level error that sums up what to fix.
When not to use
- A brief confirmation after an action: use Sonner.
- A choice the user must make before continuing: use Alert Dialog.
- A short status next to an item: use Badge.
Install
npx shadcn@latest add @clinia/alertLab results ready
CBC and metabolic panel results are now available for review.
Critical value detected
Potassium level is critically low. Immediate clinical review required.
Anatomy
API key expires in 3 days
Rotate it to keep Montreal clinic syncing.
- 1Container
data-slot="alert"border-warning · bg-warning/15 · rounded-lg - 2Icon
[data-slot=alert] > svgsize-4 · text-foreground - 3Title
data-slot="alert-title"text-sm · font-medium - 4Action (optional)
data-slot="alert-action"absolute · top-2.5 right-3
Clinia rules
warningis abg-warning/15surface with awarningborder and foreground text. The warning colour fails as text (2.30:1), so it never colours the words.destructiveandsuccesscolour the title, the description and the icon, on the card surface.- The title says what happened:
Imaging failed to sync, notError. The description says what to do next. - Put the next step in
AlertAction, as anoutlineorghostbutton.
Do and don't
Imaging failed to sync
Reconnect the source to resume.
Error
Something went wrong.
API key expires in 3 days
Source saved
States
default
Maintenance on Sunday
The console is read-only from 2 to 3 a.m.
success
Source connected
Indexing starts in a few seconds.
warning
API key expires soon
Rotate it before Friday to avoid downtime.
destructive
Sync failed
We couldn't reach the source. Check its credentials.
static note · role note
Keys are shown once
Copy the key when you create it. You can't see it again later.
Toggle the site theme to review both themes.
Accessibility
Built in
- Renders
role="alert"by default, so screen readers announce it as soon as it appears, without moving focus.roleoverrides it.
Your responsibility
role="alert"interrupts. For a static note that is part of the content at load, such as a tip in an article, passrole="note": it's read in place and never announced. For a message that appears later but isn't urgent, passrole="status".- Don't rely on the variant colour. The title must say it's an error or a warning.
- Give the action a label that names it:
Reconnect source, notFix.
How to test
- With a screen reader on, trigger the alert: it's announced right away, and focus stays where it was.
- Press Tab: focus skips the alert itself and lands on any link or button inside it.
- Toggle the site theme: every variant's text stays readable in both.
API
| Prop | Values | Default | Description |
|---|---|---|---|
| role | React.AriaRole | – | Defaults to |
| variant | defaultdestructivesuccesswarning | default |
|
All other props come from the native div element.
Related