← Back to home

Alert

Displays contextual feedback messages with heading, description, and action button. The icon is controlled by the variant via CSS.

Usage

tsx
import { Alert } from '@components-kit/react';

const handleExtend = () => {
  console.log('Session extended');
};

// Basic alert
<Alert
  heading="Information"
  description="Your settings have been updated."
  variantName="info"
/>

// With action button
<Alert
  heading="Warning"
  description="Your session will expire in 5 minutes."
  action={{
    children: "Extend Session",
    onClick: handleExtend,
  }}
  variantName="warning"
/>

Props

PropTypeDefaultDescription
headingReactNode-Main heading/title of the alert
descriptionReactNode-Body content of the alert
actionOmit<ButtonProps, "as" | "size" | "variantName">-Action button props (size fixed to "sm"). Button variant is controlled by the parent alert's variantName via CSS.
variantNameVariantFor<"alert">-Variant name for styling

Also accepts all standard div HTML attributes.

Data Attributes

AttributeValuesDescription
data-variantstringThe variant name for styling
data-has-headingtruePresent when heading is provided
data-has-actiontruePresent when action is provided
data-slot"icon", "content", "heading", "description", "action"Identifies internal slots

Accessibility

  • Uses role="alert" for immediate screen reader announcement
  • Uses aria-live="polite" to announce updates without interruption
  • Icon slot is always rendered with aria-hidden="true" (controlled via CSS per variant)
  • Action button inherits full keyboard accessibility from Button component

Best Practices

  • Keep alert messages concise and actionable
  • Use appropriate variant to match message severity
  • Provide a clear action when user response is needed
  • Don't overuse alerts — they should convey important information