Alert

Alpha

A static feedback element for communicating important messages. Uses role='alert' for errors/warnings and role='status' for info/success.

Import

import { Alert } from "@compa11y/react";

Usage

Example.tsx
import { useState } from "react";
import { Alert, Button, Link } from "@compa11y/react";

// Error alert with action
<Alert type="error" title="Payment failed">
  Your card was declined. Please try a different payment method.
</Alert>

// Success alert
<Alert type="success" title="Saved!">
  Your changes have been saved successfully.
</Alert>

// Warning with a link
<Alert type="warning" title="Session expiring">
  Your session will expire in 5 minutes. <Link href="/settings">Extend session</Link>
</Alert>

// Dismissible info
function DismissibleAlert() {
  const [visible, setVisible] = useState(true);

  if (!visible) return null;

  return (
    <Alert type="info" dismissible onDismiss={() => setVisible(false)}>
      A new version is available. <Button variant="ghost" size="sm">Update now</Button>
    </Alert>
  );
}

Features

  • role='alert' with aria-live='assertive' for error and warning types
  • role='status' with aria-live='polite' for info and success types
  • Dismiss button with aria-label='Dismiss alert' when dismissible is true
  • Four visual variants: info, success, warning, error
  • unstyled prop for full customization

Props

Alert component props
PropTypeDefaultDescription
type'info' | 'success' | 'warning' | 'error''info'Severity level — determines role and aria-live value
titlestring-Optional bold title text
dismissiblebooleanfalseShows a close button with aria-label='Dismiss alert'
onDismiss() => void-Called when the dismiss button is clicked
unstyledbooleanfalseRemoves all default styles
childrenReactNode-Alert body content

Keyboard Interactions

Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
Keyboard shortcuts for Alert
KeyAction
TabFocuses the dismiss button (when dismissible is true)
Enter / SpaceActivates the dismiss button