All components

Alert Dialog

Ask before a destructive change.

Examples

Ask before a destructive change

Discard draft?

Your unsaved changes will be lost.

React code
import {
  DialogTrigger,
  AlertDialog,
  DialogTitle,
  DialogDescription,
  DialogClose,
} from "@accelerate/react/components";

export function Example() {
  return (
    <>
      <DialogTrigger aria-controls="discard-dialog">Discard changes</DialogTrigger>
      <AlertDialog id="discard-dialog" aria-labelledby="discard-title" aria-describedby="discard-description">
        <DialogTitle id="discard-title">Discard draft?</DialogTitle>
        <DialogDescription id="discard-description">Your unsaved changes will be lost.</DialogDescription>
        <DialogClose autoFocus>Keep editing</DialogClose>
        <DialogClose>Discard draft</DialogClose>
      </AlertDialog>
    </>
  );
}
Angular code
import { Component } from "@angular/core";
import {
  AccDialogTrigger,
  AccAlertDialog,
  AccDialogTitle,
  AccDialogDescription,
  AccDialogClose,
} from "@accelerate/angular/components";

@Component({
  selector: "app-example",
  imports: [
    AccDialogTrigger,
    AccAlertDialog,
    AccDialogTitle,
    AccDialogDescription,
    AccDialogClose,
  ],
  template: `
    <button accDialogTrigger aria-controls="discard-dialog">Discard changes</button>
    <dialog accAlertDialog id="discard-dialog" aria-labelledby="discard-title" aria-describedby="discard-description">
      <h2 accDialogTitle id="discard-title">Discard draft?</h2>
      <p accDialogDescription id="discard-description">Your unsaved changes will be lost.</p>
      <button accDialogClose autofocus>Keep editing</button>
      <button accDialogClose>Discard draft</button>
    </dialog>
  `,
})
export class Example {}

Installation

Source preview. The expanded component catalog is ahead of the public npm releases. To run these examples in your own application, use packages built from the SDK source used for the previews or a release that includes the APIs below.

React
@accelerate/ui@0.4.0 and @accelerate/react@0.4.0
Angular
@accelerate/ui@0.4.0 and @accelerate/angular@0.2.0

Load @accelerate/ui/theme.css and put acc-theme on the app or the region using Accelerator components. See the framework setup guide for the theme and adapter conventions.

Usage

Use DialogTrigger, DialogTitle, DialogDescription, and DialogClose. Give the least destructive action initial focus when appropriate.

Import the React component AlertDialog from @accelerate/react/components. For Angular, add AccAlertDialog to the standalone component’s imports and use <dialog accAlertDialog>.

Examples use these React parts: DialogTrigger, AlertDialog, DialogTitle, DialogDescription, DialogClose. The Angular examples show the corresponding directives and template hosts.

API reference

aria-labelledby / aria-describedby
Connect the title and description.
autofocus
Put initial focus on the safest action.