Alert
Displays a callout for user attention.
Heads up!
You can add components to your app using the CLI.
Error
Your session has expired. Please log in again.
Alert is an inline informational block (non-modal, does not block interaction). Variants: default (info) and destructive (red). For a blocking dialog use AlertDialog; for a transient toast use Toast.
Installation
$ bext ui add alert
Copy and paste the following into src/components/ui/alert.tsx.
Usage
Anatomy
<Alert> ├── <icon /> // optional ├── <AlertTitle>Title</AlertTitle> └── <AlertDescription>Body</AlertDescription>
API Reference
Alert
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "destructive" | "default" | destructive: red border and text, and an alert-circle icon instead of the info icon. |
| iconName | string | — | Name of a built-in icon to show instead of the default one. An icon is always rendered. |
| title | string | — | Shorthand: renders an AlertTitle with this text and uses children as the description. |
| children | ReactNode | — | An AlertTitle and an AlertDescription (or the description text when title is set). |
AlertTitle
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Rendered as a <div> with font-medium, not as a heading. |
AlertDescription
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Rendered as a <div> with text-sm text-muted-foreground. |
Accessibility
role="alert" by default, so it is announced immediately to assistive technologies. Use it sparingly: the screen reader interrupts what it is reading. For a passive update, prefer role="status" aria-live="polite".
Edit this example live in the bext playground. It compiles and runs entirely in your browser.
The React idiom: same UI, for comparison.
On This Page