Skip to content

Alert

alert

An inline message in four states, with a matching icon, an optional title and room for an action. The dismiss control collapses the message out of the flow so what follows closes the gap, and only the destructive state interrupts a screen reader.

Install

$npxshadcnadd@forme/alert

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { Alert } from "@/components/forme/alert/alert";

<Alert variant="warning" title="You are at 92% of your seat limit">
  New invitations will queue once the workspace is full.
</Alert>

When to use

Reach for it

  • A message about the page or a section of it: a failed load, a limit approaching, a confirmation the reader should see next to the thing it concerns.
  • dismissible when the reader can act on the message and it should then stay gone; the close button is the acknowledgement.
  • action for the one thing to do about it — add seats, retry, update the card.

Use something else

  • Something the page will show again on reload; a dismiss that does not persist trains people to ignore it. Leave dismissible off.
  • A message that interrupts the whole task; that is a Dialog.
  • A one-off confirmation of an action just taken; that is a Toast, which does not occupy the page.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

Alert

An inline message about the page or a part of it.

PropTypeDefaultDescription
variant'info' | 'success' | 'warning' | 'destructive'"info"
titleReactNode—
iconReactNode—An icon element. Defaults to a glyph that matches the variant.
actionReactNode—Buttons or links, placed on the right on wide screens and below on narrow ones.
dismissiblebooleanfalseRenders a dismiss control. The alert animates out, then unmounts.
openboolean—Controlled visibility. Pair with onOpenChange.
defaultOpenbooleantrueWhether it starts visible when uncontrolled.
onOpenChange(open: boolean) => void—Called when the dismiss control is pressed, or when open is controlled and asked to change.
returnFocusRefReact.RefObject<HTMLElement | null>—Focus this when dismissing hides the focused control; defaults to nothing moving.

Also takes every prop of <div> attributes.

Accessibility

  • Only destructive uses role="alert", which interrupts a screen reader; the rest are role="status" and wait their turn.
  • The close button has an accessible name and, on dismissing, moves focus to returnFocusRef when it would otherwise land on the body.
  • The icon is decorative and hidden, so the message is not announced twice.

Motion

  • The entrance and exit are skipped on first render, so an alert present at page load does not animate in.
  • Dismissing collapses height and fades together, so the content below slides up rather than jumping.
  • Reduced motion drops the height change and keeps a short fade.

Responsive behaviour

  • The action sits beside the message on wide screens and below it on narrow ones, aligned with the text rather than the icon.