Skip to content

Components / Alert

Alert

Persistent inline feedback with a title, description and optional decorative icon. Use Alert for information that belongs in the page; use Alert Dialog when an action needs a modal confirmation. Alert never opens a dialog or moves focus.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.

Usage playground

Choose appearance separately from urgency. Status is polite feedback, alert is urgent feedback, and region is a named, non-live notice. These controls only edit a local preview; no request is sent.

Changes saved
Your project settings are ready for the next review.
React / TSX
'use client';

import { useId, useState } from 'react';
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/yads-alert";

const layout = { display: 'grid', gap: '1rem', width: '100%', maxWidth: '32rem', minWidth: 0 } as const;

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/alert#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

This revision-pinned command installs yads-alert, its scoped stylesheet and JetBrains Mono 5.3.0. No other primitive or icon library is installed. Import { Alert } from @/components/ui/yads-alert (adjust your alias). No Tailwind, reset, global CSS or theme provider is required. Light is the default. The nearest explicit .dark, .light or data-theme="dark|light" boundary selects colors, including nested boundaries and live changes. Explicit data-theme wins over a conflicting class; dark wins if both classes are present.

Copy sample copies a complete React module, including layout and recipe CSS, even when collapsed. Samples need only this registry item; interactive modules include a client boundary. The form sample uses native inputs and buttons, so every sample needs only Alert. Playground controls are documentation controls, not extra Alert props.

Titles, descriptions and icons

Compose either text part or both. An optional direct-child SVG gets a leading column; mark decorative icons aria-hidden and focusable=false. No icon package is required, and meaning must remain clear without the icon.

Review complete
All chapters are ready to publish.
Everything is up to date
Reviews reopen on Monday. No action is needed now.
React / TSX
'use client';

import { useId, useState } from 'react';
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/yads-alert";

const layout = { display: 'grid', gap: '1rem', width: '100%', maxWidth: '32rem', minWidth: 0 } as const;

Destructive and long content

Destructive styling does not change the role. Explain the problem and the next step in text, not just color. Descriptions accept paragraphs and lists; long words wrap without truncation.

React / TSX
'use client';

import { useId, useState } from 'react';
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/yads-alert";

const layout = { display: 'grid', gap: '1rem', width: '100%', maxWidth: '32rem', minWidth: 0 } as const;

Form result

This native form uses FormData and browser constraints. Enter submits locally, reset restores Atlas, and no data is sent. The existing status region changes text after submission; Alert does not validate fields or manage focus. Connect field-specific errors to their fields separately.

Form result
No local result yet.
React / TSX
'use client';

import { useId, useState } from 'react';
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/yads-alert";

const layout = { display: 'grid', gap: '1rem', width: '100%', maxWidth: '32rem', minWidth: 0 } as const;

className customization

Use ordinary CSS or inline style for dimensions and border weight. This complete recipe preserves scoped theme colors and keyboard focus outlines.

Review window
Keep the scoped colors and focus styles while changing the border weight.
React / TSX
'use client';

import { useId, useState } from 'react';
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/yads-alert";

const layout = { display: 'grid', gap: '1rem', width: '100%', maxWidth: '32rem', minWidth: 0 } as const;

Accessibility

  • Choose urgency deliberately. Alert defaults to role=alert, an implicitly assertive, atomic live region. Use it sparingly for urgent feedback. Override with role=status for polite, atomic updates, or a named role=region for persistent information that should not be live. Variant is independent of role. Explicit aria-live or aria-atomic props override native implicit behavior; do not create conflicting semantics or redundant nested live regions.
  • Announcements depend on timing and assistive technology. Prepopulated content on initial page render is not reliably announced, even with role=alert. Updating an already mounted region can help, but there is no announcement guarantee. The form example updates an existing status region. Browser assertions verify DOM roles and content, not physical screen-reader behavior.
  • Keep feedback readable. Supply a useful title or description and explain corrective steps. Decorative SVGs use aria-hidden=true and focusable=false; never rely only on color or an icon. Paragraphs, lists and links are supported. Text wraps without truncation.
  • Native structure stays yours. AlertTitle and AlertDescription render divs, not headings or labels. Author an appropriate heading inside AlertTitle if the page structure needs one. Use IDs with aria-labelledby and aria-describedby when useful; a region needs an accessible name. No IDs or relationships are generated automatically.
  • No modal behavior. Alert is persistent inline content, not Alert Dialog or a toast. It has no dismiss button, timeout, open state, validation engine, focus trap or focus movement. The root is not in the Tab order by default; links inside remain keyboard reachable. Applications own dismissal, focus management and field-level error associations.

Scoped CSS uses @scope to respect the nearest explicit theme, including nested light/dark islands and live class or data-theme changes. This requires browser support for CSS @scope and :has; browsers without @scope keep the light defaults rather than a guaranteed dark theme. There is no system-theme detection, provider or JavaScript theme observer.

API reference

Import { Alert, AlertTitle, AlertDescription, type AlertProps, type AlertTitleProps, type AlertDescriptionProps } from @/components/ui/yads-alert. All three forward native div props and refs. Only Alert adds variant. There is no asChild, icon prop, disabled, defaultOpen, onOpenChange or form value API.

On narrow screens, focus the table and scroll horizontally to read all columns.

Alert props, types, defaults and behavior
PropTypeDefaultDescription
Alert: variant'default' | 'destructive''default'Appearance only. Destructive uses error text and border colors; it does not change urgency or role.
Alert: roleReact.AriaRole'alert'Native override, e.g. status for polite feedback or region for a named non-live notice. No extra aria-live is imposed.
All: childrenReactNodeNot setAuthor text and structure. Title and description are optional. A direct-child SVG on Alert gets a leading icon column.
All: className / stylestring / CSSPropertiesNot setForwarded to each div while retaining its scoped class.
All: refReact.Ref<HTMLDivElement>Not setForwarded to the actual div, including object and callback refs.
All: native attributesHTMLAttributes<HTMLDivElement>Not setid, title, data-*, aria-*, role, tabIndex and native events pass through. No IDs or accessible associations are generated.

Composition and playground defaults

Place the optional SVG, AlertTitle and AlertDescription directly inside Alert to use the built-in grid. Title-only, description-only and text-only layouts work without an icon. Wrapped icon containers need consumer layout CSS; icons are never inserted automatically. Other native children are allowed, but custom layouts remain the consumer’s responsibility.

Reset restores default styling, role=status, title and description, the decorative icon and “Changes saved”. These are documentation defaults; the primitive itself defaults to role=alert with no content. Clipboard modules carry the chosen role, variant, layout and escaped title text, without the documentation controls or their dependencies.