Skip to content

Alert

An inline message about the state of the page or a task: a tip, a success, a warning or an error. For brief confirmations that disappear, use Toast.

Feedbackv0.1.0experimentalWCAG 2.2 AAView spec
Information:

Heads up

Reports are generated once a day, at 02:00 UTC.
Success:

Saved

Your changes are live.
import { Alert } from "@rdloom/react";

export default function AlertVariantsExample() {
  return (
    <div className="flex w-[28rem] max-w-full flex-col gap-3">
      <Alert title="Heads up">Reports are generated once a day, at 02:00 UTC.</Alert>
      <Alert variant="success" title="Saved">
        Your changes are live.
      </Alert>
      <Alert variant="warning" title="Storage almost full">
        You have used 92% of your plan. Uploads stop at 100%.
      </Alert>
      <Alert variant="danger" title="Payment failed">
        Your card was declined. Update it to keep your subscription.
      </Alert>
    </div>
  );
}

Installation

npx rdloom add alert

Copies the source into src/components/rdloom. Edit it freely: rdloom upgrade merges later versions into your changes. It needs react-aria-components; add --install to install them.

Use another registry client
npx shadcn@latest add https://rdloom.vimalbhatt.com/r/alert.json

Works, but without upgrade tracking.

Usage

import { Alert } from "@rdloom/react";

<div className="flex w-[28rem] max-w-full flex-col gap-3">
  <Alert title="Heads up">Reports are generated once a day, at 02:00 UTC.</Alert>
  <Alert variant="success" title="Saved">
    Your changes are live.
  </Alert>
  <Alert variant="warning" title="Storage almost full">
    You have used 92% of your plan. Uploads stop at 100%.
  </Alert>
  <Alert variant="danger" title="Payment failed">
    Your card was declined. Update it to keep your subscription.
  </Alert>
</div>

Dismissible

Information:

New: keyboard shortcuts

Press ? anywhere to see them all.
import { useState } from "react";
import { Alert, Button } from "@rdloom/react";

// onDismiss shows the close button; you decide what dismissing does.
export default function AlertDismissibleExample() {
  const [open, setOpen] = useState(true);
  return (
    <div className="flex w-[28rem] max-w-full flex-col items-center gap-3">
      {open ? (
        <Alert variant="info" title="New: keyboard shortcuts" onDismiss={() => setOpen(false)}>
          Press ? anywhere to see them all.
        </Alert>
      ) : (
        <Button variant="secondary" size="sm" onPress={() => setOpen(true)}>
          Show the message again
        </Button>
      )}
    </div>
  );
}

With action

import { Alert, Button } from "@rdloom/react";

export default function AlertWithActionExample() {
  return (
    <div className="w-[28rem] max-w-full">
      <Alert variant="danger" title="Sync failed">
        <p>We couldn&apos;t reach the server. Your changes are saved on this device.</p>
        <div className="mt-2">
          <Button size="sm" variant="secondary">
            Try again
          </Button>
        </div>
      </Alert>
    </div>
  );
}

API Reference

Defined by the spec. Components also accept the props of the React Aria component they wrap.

PropTypeDefault
childrenrequired

The message. Say what happened and what to do next.

nodenone
title

Optional bold first line, e.g. 'Payment failed'.

stringnone
variant

Tone and urgency. Warning and danger interrupt a screen reader; info and success wait their turn.

"info" | "success" | "warning" | "danger""info"
onDismiss

When set, a close button appears and calls this. You remove the alert.

() => voidnone
dismissLabel

Accessible name of the close button.

string"Dismiss"

Accessibility

Role alert, WCAG 2.2 AA. Tested with axe and keyboard tests; screen reader checks are in the audit checklist.

Keyboard

  • Tab reaches the close button, when there is one
  • Enter or Space dismisses

Screen readers announce

  • A warning or error is announced as soon as it appears, prefixed with its tone
  • An info or success message is announced after the current speech finishes
  • The close button is announced as a button named Dismiss

What your code must do

  • Warning and danger use role=alert (announced at once); info and success use role=status (announced politely)
  • The tone is also said in words for screen readers (Warning:, Error:), and shown by an icon shape, never color alone
  • The icon is decorative (aria-hidden)
  • The close button has an accessible name and a visible focus ring

Guidelines

Use it when

  • A message tied to the page or a form that stays until it is fixed or dismissed
  • Explaining why something is disabled or failed

Avoid it when

  • A short confirmation after an action: use Toast
  • A decision that blocks the user: use Dialog
  • An error on one field: use the field's own error message

Don't

  • Several alerts stacked on one screen
  • Danger tone for something that is not an error
  • Rendering an alert that is already on screen again, which re-announces it

Design tokens

The semantic tokens this component uses. Change them once and every component follows; see Design tokens.

  • --rd-color-text-default
  • --rd-color-border-default
  • --rd-color-feedback-info-subtle
  • --rd-color-feedback-success-subtle
  • --rd-color-feedback-warning-subtle
  • --rd-color-feedback-danger-subtle
  • --rd-color-feedback-info
  • --rd-color-feedback-success
  • --rd-color-feedback-warning
  • --rd-color-feedback-danger
  • --rd-color-focus-ring
  • --rd-radius-overlay