Skip to content

Alert ​

An inline, non-blocking status message. Five variants, soft or solid.

Open in demo
Open in demo

Usage ​

shadcn-vue ships an alert-dialog, which is a modal, but no inline alert. This is that: a message that sits in the page and blocks nothing.

title and description are the short form. Both have slots, and the default slot is the description, so a message with a link or a list goes in the slot instead.

Body text stays on the foreground and muted-foreground tokens rather than a tinted ramp. Colored text on a colored fill is where contrast problems live, and this has to hold in both color modes and after a buyer re-themes the primary color.

Examples ​

Variants ​

variant is default, info, success, warning or destructive. Each brings its own icon.

Solid ​

appearance="solid" is for the rare alert that has to outrank everything around it. A solid fill owns its own text color.

Actions and dismiss ​

The actions slot holds buttons under the message. dismissible adds a close button that emits dismiss; the alert does not remove itself, so you decide what dismissing means.

A different icon, or none ​

icon takes any component. Pass null for no icon at all.

API ​

Source: src/shared/components/common/SaAlert.vue

Props ​

PropTypeDefaultDescription
variant'default' | 'info' | 'success' | 'warning' | 'destructive''default'The tone, and the default icon.
titlestring—The bold first line.
descriptionstring—The body. Used when the default slot is empty.
dismissibleboolean—Adds a close button that emits dismiss.
iconComponent | null—Replaces the variant's icon. null removes it.
appearance'soft' | 'solid''soft'soft is a tinted panel, solid a filled one.

Emits ​

EventPayloadDescription
dismiss—Fires from the close button. The alert stays in the DOM.

Slots ​

SlotDescription
titleReplaces title.
defaultReplaces description.
actionsButtons under the message.

Accessibility ​

  • The root is role="alert", so a message that appears after the page has loaded is announced.
  • The icon is aria-hidden, because the variant is already carried by the title and the text.
  • The close button is named "Dismiss".
  • Soft variants keep body text on the neutral text tokens, which is what keeps them readable on the tint in both color modes.