Skip to content
Ndop UI

Alert

Displays a callout that draws the user's attention.

  • v1.0.0
  • SSR
  • Zoneless
  • 0.8 kB gzip
Your changes have been saved
Everyone on the team sees the new settings right away.
import { Component } from '@angular/core';
import { NdIcon } from '@ndop/core';
import { Alert, AlertDescription, AlertTitle } from '@/ui/alert/alert';

/** A success message with an icon, shown with the page. */
@Component({
  selector: 'example-alert-demo',
  imports: [Alert, AlertDescription, AlertTitle, NdIcon],
  template: `
    <div ndAlert role="none" class="max-w-md">
      <svg ndIcon="circle-check"></svg>
      <div ndAlertTitle>Your changes have been saved</div>
      <div ndAlertDescription>
        Everyone on the team sees the new settings right away.
      </div>
    </div>
  `,
})
export class AlertDemoExample {}

An alert is a callout that draws attention to a message: a warning, an error, a confirmation. It has an optional icon, a title and a description, laid out in a grid. It's announced with the alert role by default, which interrupts screen readers; set role="status" for news that can wait, or role="none" for a callout that's part of the page.

Installation

npx @ndop/cli add alert

Usage

import { Alert, AlertDescription, AlertTitle } from '@/ui/alert/alert';
<div ndAlert role="none" class="max-w-md">
  <svg ndIcon="circle-check"></svg>
  <div ndAlertTitle>Your changes have been saved</div>
  <div ndAlertDescription>
    Everyone on the team sees the new settings right away.
  </div>
</div>

Examples

Alert destructive

An error, with what to do about it.

Unable to process your payment

Please check your billing information and try again.

  • Check your card details
  • Make sure there are enough funds
  • Verify the billing address
import { Component } from '@angular/core';
import { NdIcon } from '@ndop/core';
import { Alert, AlertDescription, AlertTitle } from '@/ui/alert/alert';

/** An error, with what to do about it. */
@Component({
  selector: 'example-alert-destructive',
  imports: [Alert, AlertDescription, AlertTitle, NdIcon],
  template: `
    <div ndAlert variant="destructive" role="none" class="max-w-md">
      <svg ndIcon="circle-alert"></svg>
      <div ndAlertTitle>Unable to process your payment</div>
      <div ndAlertDescription>
        <p>Please check your billing information and try again.</p>
        <ul class="list-inside list-disc text-sm">
          <li>Check your card details</li>
          <li>Make sure there are enough funds</li>
          <li>Verify the billing address</li>
        </ul>
      </div>
    </div>
  `,
})
export class AlertDestructiveExample {}

Accessibility

Alert has no keyboard interaction or focus handling of its own; it keeps the semantics of the element it's on.

API reference

Alert

[ndAlert]

A callout: a message that draws attention, with an optional icon, title and description. It's announced as an alert by default; use role="status" for messages that can wait, or role="none" for ones that are part of the page from the start.

Alert binding Type Default
[variant]
Visual style.
'default' | 'destructive''default'
[role]
How assistive technology treats it: alert interrupts, status waits for a pause, none is read with the page.
'alert' | 'status' | 'none''alert'
[class]
Extra classes, merged last so they win.
string''
Data attribute Values
data-slotalert
data-variant —

AlertTitle

[ndAlertTitle]

An alert's title.

AlertTitle binding Type Default
[class]
Extra classes, merged last so they win.
string''
Data attribute Values
data-slotalert-title

AlertDescription

[ndAlertDescription]

An alert's description, under its title.

AlertDescription binding Type Default
[class]
Extra classes, merged last so they win.
string''
Data attribute Values
data-slotalert-description

Agent notes

Do

  • Write a short title that says what happened, and a description that says what to do.
  • Use variant="destructive" for errors, and say it in the text too.
  • Use role="none" for alerts rendered with the page, and keep alert for ones that appear after something the user did.

Don't

  • Don't use an alert for a notification that should disappear on its own; use a toast.
  • Don't put several role="alert" messages on a page at once.