Skip to main content
  1. Docs
  2. Components
  3. Overlays

Dialog

A focused decision or a short task, over the page. Danger and warning ask before something happens.

Import
@qeetrix/react
Status
StableSince 0.0.2
Renders
<div role="dialog">Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

dialog.tsx
// From the package: a build keeps only what it uses.
import { Dialog, DialogTrigger, DialogContent, DialogBody, DialogFooter, DialogClose } from "@qeetrix/react";

// Or from its own path.
import { Dialog, DialogTrigger, DialogContent, DialogBody, DialogFooter, DialogClose } from "@qeetrix/react/dialog";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
Dialog: open · defaultOpen · onOpenChangebooleanfalseIts open state, controlled or not.
Dialog: intent"standard" | "warning" | "danger""standard"warning and danger are alert dialogs, with an amber or red line.
Dialog: dismissiblebooleantrue; false for dangerWhether Escape, an outside click and the close button dismiss it.
DialogContent: titleReactNoderequiredThe question or the task; it labels the dialog.
DialogContent: descriptionReactNode—A line under the title; it describes the dialog.
DialogContent: size"sm" | "md" | "lg" | "xl" | "fullscreen""md"400, 560, 800 or 1120px; or the whole viewport.
DialogContent: initialFocus…the first fieldWhere focus lands as it opens.
DialogFooter: startReactNode—A quiet link or a one-line summary at the footer's start; the actions stay at its end.
DialogTrigger · DialogClose: renderReactElement—Your own control: render={<Button>…</Button>}.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
dialog-backdrop<div>The scrim.
dialog-viewport<div>Centres the dialog.
dialog-popup<div role="dialog">The dialog: data-intent, data-size; role="alertdialog" for warning and danger.
dialog-header<div>dialog-title and dialog-description.
dialog-body<div>DialogBody.
dialog-footer<div>DialogFooter.
dialog-footer-start<div>start: before the actions.
dialog-close<div>The close button, when it's dismissible.

04

Close when the work is done

Control it: close once the action has succeeded, and keep it open with the error if it fails.

delete-users.tsx
const [open, setOpen] = useState(false);

<Dialog intent="danger" open={open} onOpenChange={setOpen}>
  <DialogTrigger render={<Button tone="danger">Delete users</Button>} />
  <DialogContent title="Delete 3 users?" size="sm">
    <DialogFooter>
      <DialogClose render={<Button variant="ghost">Cancel</Button>} />
      <Button tone="danger" loading={pending} onClick={async () => { await deleteUsers(); setOpen(false); }}>Delete users</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>
Next — DialogAccessibility