Playground

Alert dialog

A modal that interrupts to confirm a destructive or irreversible action.

  • Built on native <dialog>
  • 9 parts, named exports
  • role="alertdialog" with a name from the title and a description.
  • Focus moves to the Cancel button on open and returns to the trigger on close.
  • Escape cancels; focus is trapped; the page behind is inert.
  • Styles in one file: dialog.css

Import

import '@monoline/css';
import {AlertDialog} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add alert-dialog

Usage

import {AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Button} from '@monoline/react';

<AlertDialog>
  <AlertDialogTrigger asChild><Button variant="danger">Delete project</Button></AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader><AlertDialogTitle>Delete this project?</AlertDialogTitle><AlertDialogDescription>All files and history are removed. This cannot be undone.</AlertDialogDescription></AlertDialogHeader>
    <AlertDialogFooter><AlertDialogCancel>Keep it</AlertDialogCancel><AlertDialogAction>Delete project</AlertDialogAction></AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Anatomy

Import the parts you need and nest them like this.

import {AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel} from '@monoline/react';

<AlertDialog>
  <AlertDialogTrigger />
  <AlertDialogContent />
  <AlertDialogHeader />
  <AlertDialogFooter />
  <AlertDialogTitle />
  <AlertDialogDescription />
  <AlertDialogAction />
  <AlertDialogCancel />
</AlertDialog>

Examples

Confirm a deletion

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

This component sets no state attributes.

CSS classes

ClassStylesheet
.commanddialog.css
.dialog-closedialog.css
.dialog-contentdialog.css
.dialog-descriptiondialog.css
.dialog-footerdialog.css
.dialog-headerdialog.css
.dialog-overlaydialog.css
.dialog-titledialog.css
.drawer-contentdialog.css
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.command {
  border-color: var(--accent);
}

Accessibility

  • role="alertdialog" with a name from the title and a description.
  • Focus moves to the Cancel button on open and returns to the trigger on close.
  • Escape cancels; focus is trapped; the page behind is inert.
  • Clicking the overlay does not close it.

Keyboard

KeysAction
EscapeCancels