- Docs
- Components
- 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
// 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.
| Prop | Type | Default | What it does |
|---|---|---|---|
Dialog: open · defaultOpen · onOpenChange | boolean | false | Its open state, controlled or not. |
Dialog: intent | "standard" | "warning" | "danger" | "standard" | warning and danger are alert dialogs, with an amber or red line. |
Dialog: dismissible | boolean | true; false for danger | Whether Escape, an outside click and the close button dismiss it. |
DialogContent: title | ReactNode | required | The question or the task; it labels the dialog. |
DialogContent: description | ReactNode | — | 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 field | Where focus lands as it opens. |
DialogFooter: start | ReactNode | — | A quiet link or a one-line summary at the footer's start; the actions stay at its end. |
DialogTrigger · DialogClose: render | ReactElement | — | Your own control: render={<Button>…</Button>}. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What 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.
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>