Alert
AlphaA 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
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'info' | 'success' | 'warning' | 'error' | 'info' | Severity level — determines role and aria-live value |
title | string | - | Optional bold title text |
dismissible | boolean | false | Shows a close button with aria-label='Dismiss alert' |
onDismiss | () => void | - | Called when the dismiss button is clicked |
unstyled | boolean | false | Removes all default styles |
children | ReactNode | - | Alert body content |
Keyboard Interactions
Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
| Key | Action |
|---|---|
| Tab | Focuses the dismiss button (when dismissible is true) |
| Enter / Space | Activates the dismiss button |