Confirm Button
A button that asks twice, built with definePrimitive: the first press arms it (data-armed, its text and name become labels.armed, announced), the second runs onConfirm; it disarms on a timeout, Escape or blur with change reasons, can confirm on a hold, and carries data-agent-confirm.
Example
Press twice, or hold the second one.
confirm-button-demo.tsxCopy code
Installation
Copy code
Usage
ImportCopy code
Reach for it for a quick, reversible-by-undo destructive action in a row or toolbar; ConfirmDialog when the consequence needs explaining.
API reference
ConfirmButton
| Prop | Type | Default |
|---|---|---|
agentConfirmrequiredWhat the button does, said to an agent's person before it runs: it becomes `data-agent-confirm`. | string | – |
childrenrequiredThe idle content, which names the button. | ReactNode | – |
armedChildrenThe content while armed. Defaults to `labels.armed`; it names the button then, so keep it text. | ReactNode | – |
variant | "default" | "destructive" | "outline" | "secondary" | "ghost" | "destructive" |
size | "sm" | "default" | "lg" | "default" |
labels | Partial<ConfirmButtonLabels> | – |
Also takes ConfirmButtonRoot except children, armedAnnouncement.
Other exports
confirmButtonconfirmButtonLabelstype ConfirmButtonArmedChangeReasontype ConfirmButtonConfirmReasontype ConfirmButtonOptionstype ConfirmButtonLabelstype ConfirmButtonPropsAccessibility
- A native button: once armed, its text and name become the armed label, which is also announced politely.
- Escape (only while armed), a timeout and focus leaving disarm it; holding is never the only way, since a second press confirms.
- While onConfirm's Promise runs, it is aria-busy and ignores presses.
Agent actions
Agents call confirm, which carries data-agent-confirm, so it waits for a person's approval through allow.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.