Caprice LogoCaprice UI

Alert

Displays a callout for user attention.

Installation

npx shadcn@latest add @caprice/alert

Usage

import * as Alert from "@/components/caprice-ui/alert"
<Alert.Root>
  <CheckCircle2Icon />
  <Alert.Title>Success! Your changes have been saved</Alert.Title>
  <Alert.Description>This is an alert with icon, title and description.</Alert.Description>
</Alert.Root>

Examples

Icon

info

Warning

Success

Destructive

Dismissible

Custom

Differences with shadcn/ui / Radix

If you're familiar with Radix UI and shadcn/ui, most patterns will carry over. This guide points out the differences so you can start using Caprice UI without surprises.

Key changes

Featureshadcn/uiCaprice UI
PrimitiveNative <div> elementsBase UI useRender + native <div>
CompositionNonerender prop
API patternFlat exports (Alert, AlertTitle)Namespace pattern (Alert.Root, Alert.Title)
Variantsdefault, destructivedefault, success, info, warning, destructive
Border radiusrounded-lgrounded-xl
Destructive styletext-destructive bg-cardborder-destructive/30 bg-destructive/5 with icon coloring
Semantic colorsNot includedsuccess, info, warning with opacity-based bg/border

Comparison Example

shadcn/ui
<Alert variant="destructive">
  <AlertCircle className="h-4 w-4" />
  <AlertTitle>Error</AlertTitle>
  <AlertDescription>Something went wrong.</AlertDescription>
</Alert>
Caprice UI
<Alert.Root variant="destructive">
  <AlertCircle />
  <Alert.Title>Error</Alert.Title>
  <Alert.Description>Something went wrong.</Alert.Description>
</Alert.Root>

Accessibility

  • Live region: The component uses role="alert" which creates an ARIA live region with implicit aria-live="assertive" and aria-atomic="true". Screen readers announce the alert content immediately when it appears in the DOM.
  • Use sparingly: Because alerts interrupt the user's workflow, reserve them for important, time-sensitive information. Overusing alerts can frustrate users and diminish their effectiveness.
  • Don't rely on color alone: Each variant (success, warning, destructive, info) should be paired with an icon and descriptive text. The component automatically colors icons to match the variant, but the message content should make the alert's purpose clear without color.
  • Dismissible alerts: When using a dismiss button, ensure it has an accessible name (e.g., aria-label="Dismiss alert") and is keyboard accessible.
  • No focus management: Alerts don't automatically receive focus—this is intentional per WAI-ARIA guidelines. If the alert requires user action, consider using an Alert Dialog instead.
  • Dynamic alerts: For alerts that appear after user interaction (e.g., form validation), the live region ensures the message is announced. Avoid removing alerts too quickly; give users time to read and comprehend the content.

Variants

Prop

Type

API Reference

Root

Prop

Type

Title

Prop

Type

Description

Prop

Type