Navigated to /docs/ui/components/confirm-dialog

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.

TSX
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

Use `ConfirmDialog` for confirmation flows

Choose something else when

Avoid ConfirmDialog when using feedback components as primary page layout.

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

TSXCreate: src/components/examples/ConfirmDialogExample1.tsx
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.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
openboolean

Configures open for this component.
titleChild

Configures title for this component.
descriptionChild

Configures description for this component.
confirmLabelChild

Configures confirmLabel for this component.
cancelLabelChild

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

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by ConfirmDialog.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by ConfirmDialog.

idstring

No

Inherited id attribute accepted by ConfirmDialog.

rolestring

No

Inherited role attribute accepted by ConfirmDialog.

styleRecord<string, unknown>

No

Inherited style attribute accepted by ConfirmDialog.

titlestring & Child

No

Configures title for this component.

tabIndexnumber

No

Inherited tabIndex attribute accepted by ConfirmDialog.

hiddenboolean

No

Inherited hidden attribute accepted by ConfirmDialog.

disabledboolean

No

Inherited disabled attribute accepted by ConfirmDialog.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by ConfirmDialog.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by ConfirmDialog.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by ConfirmDialog.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by ConfirmDialog.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by ConfirmDialog.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by ConfirmDialog.

openboolean

No

Configures open for this component.

descriptionChild

No

Configures description for this component.

confirmLabelChild

No

Configures confirmLabel for this component.

cancelLabelChild

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

ConcernContract
StateUse open to supply rendered state. Update it through the documented callback or native event handler.
DOM targetRoot passthrough props target the overlay. Use labelledBy and describedBy for the inner dialog's accessible name and description.

Anatomy and related components

This component exposes one public component root rather than a compound member API.

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

ContractCurrent value
Maturitystable
Categoryfeedback
Component import@tavojs/ui/confirm-dialog
Explicit CSS import@tavojs/ui/css/confirm-dialog
PreviewInteractive preview available on this page