Veil UI
Components

Alert

Communicates a short, important message inline with the page.

Installation

$ npx veil-ui@latest add alert

Usage

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";

<Alert>
  <AlertTitle>Heads up</AlertTitle>
  <AlertDescription>Something changed.</AlertDescription>
</Alert>;

Examples

Basic

Destructive

With icon

With action

API reference

PropTypeDefaultDescription
variant"default" | "destructive""default"Visual style of the alert.
...propsReact.ComponentProps<"div">—All native div attributes.

Accessibility

  • The root uses role="alert", so it is announced when inserted into the DOM. Static alerts rendered on page load can be wrapped in a div without the role if the announcement would be noisy.
  • Do not convey status through color alone; keep an icon or a text label.
  • Actions inside the alert should be reachable by keyboard in reading order.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add alert --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { computed } from "vue";

import { cn } from "@/lib/utils";

import { alertVariants, type AlertVariants } from "./variants";

const props = defineProps<{
  class?: string;
  variant?: AlertVariants["variant"];
}>();

const classes = computed(() =>
  cn(alertVariants({ variant: props.variant }), props.class),
);
</script>

<template>
  <div
    data-slot="alert"
    :data-variant="variant ?? 'default'"
    role="alert"
    :class="classes"
  >
    <slot />
  </div>
</template>

On this page