Skip to content
kerfjsGitHub

TypeToConfirm

Makes people type a name before an action that cannot be undone.

SourcePackage @kerf-js/veneer

Preview

tsx
import { state } from '@kerf-js/core'import { Button, TypeToConfirm } from '@kerf-js/veneer'export function Delete() {  const open = state(false)  const gone = state(false)  const confirm = async () => {    await wait(700)    gone.value = true  }  return (    <>      {gone.value ? (        <Button          emphasis="ghost"          tone="neutral"          onClick={() => (gone.value = false)}        >          reports deleted. Put it back        </Button>      ) : (        <Button          tone="critical"          onClick={() => (open.value = true)}        >          Delete reports        </Button>      )}      <TypeToConfirm        open={open}        title="Delete reports?"        description="This can't be undone."        confirmText="reports"        items={[          '41 deploys and their logs',          '3 scheduled jobs',        ]}        action="Delete project"        onConfirm={confirm}      />    </>  )}const wait = (ms: number) =>  new Promise<void>((done) => {    setTimeout(done, ms)  })

Installation

npm install @kerf-js/veneer

Usage

tsx
import { TypeToConfirm } from '@kerf-js/veneer'

Accessibility

Enter
Confirms once the text matches
Esc
Cancels and returns focus
  • Focus goes to the field, not to Cancel, because typing is the next step.

API Reference

PropTypeDefaultDescription
openState<boolean>—Whether it shows. You own this state.
titleunknown—The heading.
descriptionunknown—One supporting line under the title.
confirmTextstring—The exact text to type.
itemsstring[]—What goes, listed.
actionunknown—The confirm button's words.
glyphstring | IconComponentTrashIconThe icon at the top.
EventTypeDefaultDescription
onConfirm() => void | Promise<void>—Do the work here. A thrown error keeps the dialog and offers Retry.

Parts

Every element carries a stable name, so you can style it from your own CSS: [data-scope="confirm"] [data-part="mark"]

mark

RelatedConfirm dialogDanger zone