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 add alertAnatomy
Import the parts and combine them. The AlertIndicator automatically renders an icon that matches the status of the surrounding Alert.
import {
Alert,
AlertIndicator,
AlertContent,
AlertTitle,
AlertDescription
} from "@/components/tailgrids/core/alert";
export default () => (
<Alert status="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, error, 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 status 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 status context to all child parts.
| Prop | Type | Default | Description |
|---|---|---|---|
status | 'default' | 'success' | 'warning' | 'error' | '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-status | 'default' | 'success' | 'warning' | 'error' | 'info' | Reflects the current status prop |
AlertIndicator
Renders the status-aware icon. Pass children to override the default icon.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | React.ReactNode | status icon | Override the default status icon |
| Data Attribute | Values | Description |
|---|---|---|
data-slot | 'alert-indicator' | Identifies the alert indicator |
data-status | 'default' | 'success' | 'warning' | 'error' | 'info' | Reflects the current status 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-status | 'default' | 'success' | 'warning' | 'error' | 'info' | Reflects the current status prop |
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-status | 'default' | 'success' | 'warning' | 'error' | 'info' | Reflects the current status 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
statusis 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 status-aware parts also exposedata-status. These are useful for styling and for accessibility-related tests.
