Alert
React Alert components are used to show important messages or feedback after user actions. They are commonly used to confirm actions, show errors, display warnings, or share system information.
This Alert component is built with React and styled using Tailwind CSS, allowing control over layout, content, and visual style.
Success
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli@latest add alertAnatomy
Import the parts and combine them. The AlertIndicator automatically renders an icon that matches the variant of the surrounding Alert.
import {
Alert,
AlertIndicator,
AlertContent,
AlertTitle,
AlertDescription
} from "@/components/tailgrids/alert";
export default () => (
<Alert variant="success">
<AlertIndicator />
<AlertContent>
<AlertTitle>Success</AlertTitle>
<AlertDescription>
Your changes have been saved successfully.
</AlertDescription>
</AlertContent>
</Alert>
);Examples
Basic
Compose different parts to create an alert according to your needs.
You have 3 unread messages
Success
Your account settings have been updated.
Variants
The Alert component includes five semantic variants, each with their own color scheme: default, success, warning, destructive, and info.
Default
Success
Warning
Error
Information
With Actions
Render buttons or links inside <AlertContent> to give users a way to act on the alert.
Settings
Custom Icon
Pass any icon as a child of <AlertIndicator> to override the default variant icon.
New features available
Flexibility
As each part is a separate sub-component, you can customize the layout and content of the alert to suit your needs.
Your account settings have been updated.
Scheduled maintenance
Storage almost full
There were 2 problems with your submission
- Email address is required
- Password must be at least 8 characters
API Reference
Alert
The root container. Provides variant context to all child parts.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'success' | 'warning' | 'destructive' | 'info' | 'default' | Sets the alert style and tone |
className | string | - | Additional CSS classes |
children | React.ReactNode | - | AlertIndicator, AlertContent |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert' | Identifies the alert root element |
data-variant | 'default' | 'success' | 'warning' | 'destructive' | 'info' | Reflects the current variant prop |
AlertIndicator
Renders the variant-aware icon. Pass children to override the default icon.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | React.ReactNode | variant icon | Override the default variant icon |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert-indicator' | Identifies the alert indicator |
data-variant | 'default' | 'success' | 'warning' | 'destructive' | 'info' | Reflects the current variant prop |
AlertContent
The container that groups the title, description and other content.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes |
children | React.ReactNode | AlertTitle, AlertDescription, and any content |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert-content' | Identifies the alert content row |
AlertTitle
The alert heading.
| Prop | Type | Default | Description |
|---|---|---|---|
level | number | 4 | Heading level, from 1 to 6 |
render | (props, renderProps) => ReactElement | - | Custom DOM renderer for the heading element |
className | string | - | Additional CSS classes |
style | React.CSSProperties | - | Inline styles |
children | React.ReactNode | - | Title text |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert-title' | Identifies the alert title |
data-variant | 'default' | 'success' | 'warning' | 'destructive' | 'info' | Reflects the current variant prop |
AlertAction
Optional slot pinned to the top-right corner of the alert, for a close button or another action. The root adds right padding when an AlertAction is present.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes |
children | React.ReactNode | Action content |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert-action' | Identifies the alert action |
AlertDescription
The alert body.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes |
children | React.ReactNode | Description body |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert-description' | Identifies the alert description |
data-variant | 'default' | 'success' | 'warning' | 'destructive' | 'info' | Reflects the current variant prop |
Accessibility
- Live announcement: The root renders with
role="alert", so assistive technologies announce it immediately when it appears in the DOM. - Heading structure:
AlertTitleuses React Aria'sHeadingcomponent. It defaults tolevel={4}, and you can pass a differentlevelwhen you need another heading depth. - Status is not color-only: Each
variantis paired with a dedicatedAlertIndicatoricon, so the message still has a visual cue beyond color alone. - Indicator is decorative by default: The indicator is intended to be decorative, so it's been hidden from assistive technologies using
aria-hidden="true"androle="presentation". - Content semantics:
AlertDescriptionis a generic content wrapper in the implementation, so you can include plain text, links, lists, or action buttons inside it when needed. - Testing hooks: Every subcomponent exposes a
data-slotattribute, and variant-aware parts also exposedata-variant. These are useful for styling and for accessibility-related tests.
