Search docs

Alert

A message that draws attention without interrupting the user.

Alert follows the Alert WAI-ARIA design pattern.

import { component$, useStyles$ } from '@builder.io/qwik';
import { Alert } from '@leve-ui/alert';
import { LuAlertCircle } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <Alert.Root class="alert-default">
      <LuAlertCircle class="alert-default-icon" aria-hidden="true" />
      <Alert.Title class="alert-default-title">Payment failed</Alert.Title>
      <Alert.Description class="alert-default-description">
        Check your card details and try again.
      </Alert.Description>
    </Alert.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/alert

Anatomy#

import { Alert } from '@leve-ui/alert'; // or '@leve-ui/core'

<Alert.Root>
  <Alert.Title />
  <Alert.Description />
</Alert.Root>
PartElementDescription
Alert.Root<div>Wraps the message and has role="alert" (unless live={false}).
Alert.Title<div>The heading of the message.
Alert.Description<div>The body of the message.

Examples#

On Submit#

Render Alert.Root at the moment the message should be announced, for example after a failed submit.

API Reference#

Root#

PropDefaultType
livetrueboolean

Whether the alert is a live region (role={live === false ? undefined : 'alert'} data-live={live === false ? undefined : ''}) that screen readers announce. Set it to false for a notice that is on the page from the start, so that it is read as normal content.

Also accepts all <div> attributes.

Data attributeValue
data-leve-alertAlways present

live (default true) decides whether the Root is a live region. Use live={false} for static notices.

Title#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-alert-titleAlways present

Description#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-alert-descriptionAlways present

Accessibility#

Complies with the Alert WAI-ARIA design pattern.

  • Alert.Root renders role="alert", so screen readers announce its content.
  • An alert that is already in the page when it loads may not be announced. Render it when it should be shown.
  • For a notice that is on the page from the start (for example a banner about the page itself), pass live={false}: the Root renders no role and is read as normal content.
  • Alert does not move focus and does not close itself. For temporary notifications, use a toast instead.
  • Alert has no keyboard interaction.