Skip to content

React Alert Component

A glass React alert component for inline messages, with four tones, an optional action and a dismiss button, announced by screen readers.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/alert.json

Saving your draft

Syncing 3 changes to the cloud.

Four tones

Each tone has its own icon and tint. The words always say what happened.

A new version is available

Reload the page to get the latest features.

Changes saved

Your profile is up to date.

Storage almost full

You have used 92% of your plan.

Payment failed

Your card was declined. Update it to keep your plan.

Files to copy

6 folders · 7 files · 4 packages
From theme/src/
  • components/alert/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, motion-props.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/alert.jsonRegistry item: alert. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/spinner/
  • hooks/{use-latest.ts, use-magnetic.ts}
  • motion/gate.ts
  • lib/{form.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Action and dismiss

Put a real button or link in action. dismissible adds a close button; open and onOpenChange let you control it.

Your trial ends in 3 days

Add a payment method to keep your projects.

Props

PropTypeDefaultDescription
tone"success" | "warning" | "danger" | "info""info"Sets the colour role and the default icon of the alert.
titleReactNodeNoneA bold first line shown above the message.
iconReactNodeNoneReplaces the tone's icon; false hides it.
actionReactNodeNoneA button or link at the end, such as "Undo" or "Upgrade". Keep it a real control.
dismissiblebooleanfalseShow a close button. The alert hides itself when it is pressed.
openbooleanNoneWhether the alert is shown (controlled). Pair with onOpenChange.
defaultOpenbooleantrueWhether the alert starts shown when uncontrolled.
onOpenChange((open: boolean) => void)NoneCalled with false when the dismiss button is pressed.
labelsPartial<AlertLabels>defaultAlertLabelsEvery other string, for translation: labels={{ dismiss: "…" }}; omitted keys keep the English of defaultAlertLabels. Its only key is listed in the key table under the props table.
role"alert" | "status" | "none" | …alert for warning and danger, otherwise statusSets the live-region role that announces the alert.
AlertLabels keys and English defaults (1)
Pass any key in labels; the rest keep the defaults of defaultAlertLabels.
KeyEnglish default
dismissDismiss

Keyboard

KeysAction
TabMoves to the action and the dismiss button; the alert itself is not a tab stop.
Enter/SpaceActivates the focused action or the dismiss button.

Accessibility

  • Warning and danger use role="alert" (announced at once); info and success use role="status" (announced politely). Pass role="none" for a message that is already on screen at page load: the live demos on this page do, so navigating here does not read out five alerts (the code samples show normal use).
  • The tone icon is decorative. The title and message carry the meaning, color is only a hint.
  • The dismiss button is named by labels.dismiss, is 44px on touch screens, and has a visible focus ring.
  • Text sits on a near-opaque tinted surface, so it keeps 4.5:1 over glass, photos and blobs in light and dark. Forced colors draw a CanvasText border.

When to use Alert

  • Use Alert as an inline message in React for a form-level error above a checkout form, such as a declined card, where the message must stay on screen next to the fields the person has to fix.
  • Use it for a plan-limit banner at the top of a settings page, with an action button like Upgrade placed at the end of the row and a close button for people who have seen it.
  • Use the success tone for a saved confirmation that should remain readable until the next navigation, instead of vanishing the way a toast does after a few seconds.
  • Skip it when the message should disappear by itself after a short moment or must block the page until answered. Use Toast for the first case and Dialog or AlertDialog for the second.
  • Pair it with Button for the action slot, Field or Input for the form it explains, and Toast for the lighter follow-up feedback once the problem is fixed.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .