ConfirmDialog
Confirmation dialog composition for important or destructive actions.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { ConfirmDialog } from "@tavojs/ui/confirm-dialog";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/confirm-dialog.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
ConfirmDialog example
tsximport { createTavo } from "@tavojs/core";
import { ConfirmDialog } from "@tavojs/ui/confirm-dialog";
import { Button, Text } from "@tavojs/ui";
type State = { open: boolean; removed: boolean };
export const ConfirmDialogExample1 = createTavo<Record<string, never>, State>({
model: () => ({ open: false, removed: false }),
view: ({ state, model }) => (
<>
<Button id="remove-draft-trigger" onClick={() => model.set("open", true)} disabled={state.removed}>Remove draft</Button>
<ConfirmDialog
open={state.open}
title="Remove draft?"
labelledBy="remove-draft-title"
description="This demo only changes local state."
use={(overlay: HTMLDivElement) => { overlay.querySelector("button")?.focus(); }}
onConfirm={() => {
model.patch({ open: false, removed: true });
document.getElementById("remove-draft-status")?.focus();
}}
onCancel={() => {
model.set("open", false);
document.getElementById("remove-draft-trigger")?.focus();
}}
/>
<Text id="remove-draft-status" role="status" tabIndex={-1}>{state.removed ? "Draft removed from this demo." : "Draft available."}</Text>
</>
)
});Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
open | boolean | — | Configures open for this component. |
title | Child | — | Configures title for this component. |
description | Child | — | Configures description for this component. |
confirmLabel | Child | — | Configures confirmLabel for this component. |
cancelLabel | Child | — | Configures cancelLabel for this component. |
tone | "primary" | "danger" | — | Configures tone for this component. |
onConfirm | () => void | — | Configures onConfirm for this component. |
onCancel | () => void | — | Configures onCancel for this component. |
Complete TypeScript API
Import from @tavojs/ui/confirm-dialog. Published exports: ConfirmDialog, ConfirmDialogProps.
ConfirmDialogProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by ConfirmDialog. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by ConfirmDialog. |
id | string | No | Inherited id attribute accepted by ConfirmDialog. |
role | string | No | Inherited role attribute accepted by ConfirmDialog. |
style | Record<string, unknown> | No | Inherited style attribute accepted by ConfirmDialog. |
title | string & Child | No | Configures title for this component. |
tabIndex | number | No | Inherited tabIndex attribute accepted by ConfirmDialog. |
hidden | boolean | No | Inherited hidden attribute accepted by ConfirmDialog. |
disabled | boolean | No | Inherited disabled attribute accepted by ConfirmDialog. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by ConfirmDialog. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by ConfirmDialog. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by ConfirmDialog. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by ConfirmDialog. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by ConfirmDialog. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by ConfirmDialog. |
open | boolean | No | Configures open for this component. |
description | Child | No | Configures description for this component. |
confirmLabel | Child | No | Configures confirmLabel for this component. |
cancelLabel | Child | No | Configures cancelLabel for this component. |
tone | "danger" | "primary" | No | Configures tone for this component. |
onConfirm | () => void | No | Configures onConfirm for this component. |
onCancel | () => void | No | Configures onCancel for this component. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Use open to supply rendered state. Update it through the documented callback or native event handler. |
| DOM target | Root passthrough props target the overlay. Use labelledBy and describedBy for the inner dialog's accessible name and description. |
Anatomy and related components
Limitations
Avoid ConfirmDialog when using feedback components as primary page layout.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Built on `Dialog`, so it inherits modal roles, escape behavior, and focus trapping.
Built on `Dialog`, so it inherits modal roles, escape behavior, and focus trapping.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | feedback |
| Component import | @tavojs/ui/confirm-dialog |
| Explicit CSS import | @tavojs/ui/css/confirm-dialog |
| Preview | Interactive preview available on this page |