Skip to Content
zjkm-ui
Components

Type-to-Confirm Dialog

A dialog that asks you to type a name before deleting.

Delete acme-web?

This deletes the project, its deployments and its data.

Props
<TypeToConfirmDialog open={open} confirmText="acme-web" onConfirm={remove} onCancel={close} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/type-to-confirm-dialog.json
import { TypeToConfirmDialog } from "@/components/type-to-confirm-dialog"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

For actions that can't be undone: the Delete button stays disabled until the thing's name is typed exactly. It's a native modal <dialog>: focus moves in and stays there, Escape closes it, and the page behind can't be reached.

import { TypeToConfirmDialog } from "@/components/type-to-confirm-dialog";

export function DeleteProject({ name, remove }: { name: string; remove: () => void }) {
  const [open, setOpen] = useState(false);
  return (
    <>
      <button onClick={() => setOpen(true)}>Delete project</button>
      <TypeToConfirmDialog open={open} title={`Delete ${name}?`} description="This can't be undone." confirmText={name} onConfirm={remove} onCancel={() => setOpen(false)} />
    </>
  );
}

Props

PropTypeDefaultDescription
openbooleanShows the dialog.
titlestringThe question.
descriptionstringWhat will be lost.
confirmTextstringWhat must be typed.
confirmLabelstring"Delete"Confirm button text.
onConfirm() => voidCalled on confirm.
onCancel() => voidCalled on Cancel or Escape.

With reduced motion, it appears without scaling in.

On this page