Modal confirmation
A question with a yes and a no, over the page, before something that cannot be undone. The second piece of the Modal.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Delete this agent?" description="Its keys stop working at once. This cannot be undone." confirmLabel="Delete" destructive onConfirm={remove}/>Installation
import { ModalConfirmation } from "@catalog-dashboard/components";It is in the Modal's file (ds/components/modal.tsx), built on the primitive shadcn's Alert Dialog uses (Base UI's), with the Card's title and description inside.
Anatomy
- 1 · The box. The Modal's box, 384px wide, padded 16px.
- 2 · Title. The question. 13px, medium.
- 3 · Description. What a yes does, in a sentence.
- 4 · No. Closes it. The focus lands here.
- 5 · Yes. Primary, or red when it destroys.
Each part, and when it shows
Without children it is a fixed shape: a title, a description and two Buttons, with no line, no body and no X. With a form as its children it takes the Modal's frame: a header (the title, the description under it) with its line, the form as the body, and a footer with its line holding the same two full-width buttons.
| Part | What it is | When it shows |
|---|---|---|
| The cover | Black at 40% over the whole page, 60% in dark. A click on it does nothing. | Under an open confirmation. |
| The box | The Modal's box: the card's fill, 12px corners, the deepest of the four shadows. 384px wide, padded 16px. | While open is true. |
| The title | The question: 13px, medium. | Always. |
| The description | What a yes does, in the secondary text color, under the title. | When description is given. |
| The no | A Button, at the left: the neutral one. “Cancel” unless cancelLabel says otherwise. It closes the confirmation. cancelButton passes it the Button's own props. | Always. |
| The yes | A Button, at the right: the primary one, red with destructive. “Confirm” unless confirmLabel says otherwise. confirmButton passes it the Button's own props. | Always. |
By their presets the two buttons are 28px tall. They are 12px apart, each takes half the width (170px), and they sit 16px under the text.
Before a deletion
A title, a description, and two buttons that share the width. The no comes first, and the focus lands on it. destructive is a preset: it makes the yes red. The yes does not close the confirmation: the screen decides when it is open, with open, and closes it when the work is done. While the work runs, the screen sets the yes's own loading and disables the no. A failure has no place in the confirmation: the screen reports it, with the toast every failed change uses.
const [open, setOpen] = useState(false);const [deleting, setDeleting] = useState(false); async function remove() { setDeleting(true); try { await deleteAgent(); setOpen(false); } catch (error) { toast(mutationFailureToast("agent", "delete", error)); } finally { setDeleting(false); }} <ModalConfirmation open={open} onOpenChange={setOpen} title="Delete this agent?" description="Its keys stop working at once. This cannot be undone." confirmLabel={deleting ? "Deleting" : "Delete"} destructive confirmButton={{ loading: deleting, loadingPlacement: "before" }} cancelButton={{ disabled: deleting }} onConfirm={remove}/>A yes that is not red
Without destructive the yes is the primary button.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Rotate the signing key?" description="New tokens are signed with the new key. Tokens already issued stay valid until they expire." confirmLabel="Rotate" onConfirm={rotate}/>Its two buttons are Buttons
destructive and the two labels are presets. Anything else about a button is the Button's own prop, passed with confirmButton or cancelButton, over the preset: an icon, another emphasis, another size. The confirmation has no prop of its own for any of it.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Delete this agent?" description="Its keys stop working at once. This cannot be undone." confirmLabel="Delete" destructive confirmButton={{ iconStart: Trash }} cancelButton={{ emphasis: "ghost" }} onConfirm={remove}/>At work
The confirmation has no state of its own for this. A yes at work is the Button's loading, passed with confirmButton: here with loadingPlacement="before", the Loader, then the word, with no “…” after it. The screen disables the no with cancelButton. The two buttons keep their width, and the yes does not fire again. The Escape key still asks to close it: onOpenChange is called, and the screen may ignore it until the request ends.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Delete this agent?" description="Its keys stop working at once. This cannot be undone." confirmLabel="Deleting" destructive confirmButton={{ loading: true, loadingPlacement: "before" }} cancelButton={{ disabled: true }} onConfirm={remove}/>A title alone
The description can be left out when the title says it all.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Discard your changes?" confirmLabel="Discard" cancelLabel="Keep editing" destructive onConfirm={discard}/>With a form inside
When the answer needs something more (a choice, a picker, a name typed to go on: 2 or 3 fields at most), the form is its children. It then takes the Modal's frame: the line under the header, the sentence still under the title, the form as one section of the body, the line over the buttons. The two buttons stay full width, and so does every control in the form. It keeps its one width.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Delete billing-bot?" description="Its keys stop working at once. This cannot be undone." destructive confirmLabel="Delete" onConfirm={remove}> <Field title="To continue, type billing-bot below."> <Input value={typed} onChange={(e) => setTyped(e.target.value)} /> </Field></ModalConfirmation>A result, one button
A result asks nothing: cancel={false} leaves the yes alone, full width. What to copy goes in the form.
<ModalConfirmation open={open} onOpenChange={setOpen} title="Webhook trigger created" description="Copy the signing secret now — it is shown only once." confirmLabel="Done" cancel={false} onConfirm={() => setOpen(false)}> <Field title="Signing secret"> <Input readOnly value={secret} /> </Field></ModalConfirmation>Keyboard and focus
Measured in a browser, on the real confirmation.
| Key | Does |
|---|---|
(on opening) | The focus goes to the no. Measured with a mouse and a keyboard, not on a touch screen. |
Tab, Shift + Tab | Between the no and the yes: the focus stays in the confirmation. |
Enter, Space | Presses the button that has the focus. |
Escape | Closes it. The focus goes back to what opened it. |
While it is open, the page behind does not scroll and does not answer the pointer. A click on the cover does not close it: the answer is one of the two buttons, or the Escape key.
Accessibility
A screen reader is told that it is an alert dialog (the role alertdialog). It reads the title as its name, and the description after it. The title is a level-2 heading. While it is open the rest of the page is hidden from a screen reader.
A yes whose Button is loading says it is busy. What a screen reader says when one opens was not tested.
In the dashboard
50 yes/no dialogs draw it today. The ones still on the older dialogs hold a list that grows with the data, or more than 3 fields. An error line can stay inside it (a billing step that failed): under the sentence, or its form's last line, just above the buttons.
The shared confirmation
ConfirmDialog draws it for 32 confirmations: a title, a description, Cancel and a yes that is red when it destroys. Its consequence is a second, heavier line in the description; while the yes is at work, the yes shows its loading and Cancel waits.
components/shared/confirm-dialog.tsx
Confirmations on their own
15 more draw it directly: removing a card, deleting a judge or a subscription, discarding rule edits, the unsaved-changes guard; and, with a small form, rotating an agent key (a gateway picker), resetting a rate override (a choice), blocking a tool (a reason), the assistant's broad actions (a checkbox), and the two shown-once secrets (Done alone).
ds/components/modal.tsx
API Reference
ModalConfirmation
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | — | Required. Whether it is open: the screen decides. |
onOpenChange | (open, details) => void | — | Required. Called when it asks to close: the no, the Escape key. details.reason says which. |
title | ReactNode | — | Required. The question. |
description | ReactNode | — | What a yes does, in a sentence. |
confirmLabel | string | "Confirm" | The yes. |
cancelLabel | string | "Cancel" | The no. |
destructive | boolean | false | A preset: the yes destroys something, so it is red. |
confirmButton | ButtonPresetProps | — | The yes's own props, over its preset: the Button's (iconStart, emphasis, size, loading, disabled…), each optional, with loadingPlacement still tied to its icons. |
cancelButton | ButtonPresetProps | — | The no's own props, over its preset: the Button's, as for the yes. |
onConfirm | () => void | — | Required. Runs on a yes. It does not close the confirmation: the screen does, when the work is done. |
children | ReactNode | — | A form the answer needs. With it, the Modal's frame: a line under the header, the form as the body, a line over the buttons. |
cancel | boolean | true | false: no Cancel, the yes alone and full width (a result). |
Tokens
The Modal's, in ds/tokens/modal.css: none is the confirmation's own.
| Token | Value | What it sets |
|---|---|---|
--modal-background | The card's fill | The box's fill. |
--modal-shadow | Stacking level 4 | The box's edge and shadows. |
--modal-backdrop | Black at 40%, 60% in dark | The cover over the page (the backdrop). |
--modal-width-sm | 384px | The box's width, its only one. |
Rules
Written down
A yes/no is a Modal confirmation
A dialog that asks a yes or no about a warning or a question is the Modal confirmation, never a Modal with a description. With a form inside, it keeps the Modal's lines and the full-width buttons.
From The designer, Nov 24.
Its form is very small
A confirmation's form holds 2 or 3 fields at most. Anything bigger is a Modal.
From The designer, Nov 24.
Its form fills its width, and it has one size
Every control in a confirmation's form is full width (a Select's trigger takes width="fixed"). The confirmation has one width, 384px, with a form or without; a long value is cut in its field, never wider.
From The designer, Nov 24.
Confirm only what cannot be undone
No “are you sure?” on a safe action. A confirmation is for a revoke, a rollback, a delete.
From design/principles.md (Voice & Posture).
The yes is at the right, the no at its left
The button that does the thing sits at the right. Cancel is the button at its left.
From design/principles.md (Forms).
A component that holds another passes it through
The confirmation holds two Buttons. It re-exposes none of their behavior as a prop of its own: destructive and the two labels are presets, and confirmButton and cancelButton pass the Button's own props.
From ui/ds/README.md (Components).
A button shows its own loading while its request runs
A yes at work is the Button's loading, set by the screen through confirmButton.
From .claude/rules/dashboard-ui.md (rule 6).
A failed change says so with the shared toast
A confirmation has no place for an error. When its yes fails, the screen reports it with mutationFailureToast, as every failed change does.
From ui/dashboard/CLAUDE.md (Failed-mutation toasts).
Open questions
They are on the Modal's page, each with a picture. Three of them are about this piece too: whether its buttons are 28px or 32px, whether it gets a row for an error, and whether it is called Modal confirmation or Alert dialog.