Components
Type-to-Confirm Dialog
A dialog that asks you to type a name before deleting.
<TypeToConfirmDialog open={open} confirmText="acme-web" onConfirm={remove} onCancel={close} />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/type-to-confirm-dialog.jsonimport { 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
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | Shows the dialog. | |
title | string | The question. | |
description | string | What will be lost. | |
confirmText | string | What must be typed. | |
confirmLabel | string | "Delete" | Confirm button text. |
onConfirm | () => void | Called on confirm. | |
onCancel | () => void | Called on Cancel or Escape. |
With reduced motion, it appears without scaling in.