Modal & Overlay

Unlock Dialog

A non-dismissable modal access-code prompt — no backdrop click, no Escape-to-close.

modaldialog

Best used for Triggering an unlock prompt from a custom button or menu item instead of gating content directly.

The modal shell <ProtectedModal> renders internally, exposed on its own for cases where you want to trigger an unlock prompt manually rather than gating a whole content region.

Loading preview…
Installation

Add this block to your project

CLI

npx shadcn@latest add http://localhost:3000/r/react/unlock-dialog.json

Running this site somewhere other than localhost? Set NEXT_PUBLIC_SITE_URL and this command switches to that host automatically.

Also installs

  • Knock Codes Core
  • Knock Codes Types
  • PIN Input

Files created (7)

  • components/knock-codes/core/hash.ts
  • components/knock-codes/core/verify.ts
  • components/knock-codes/core/session.ts
  • components/knock-codes/core/storage.ts
  • components/knock-codes/react/types.ts
  • components/knock-codes/react/PinInput.tsx
  • components/knock-codes/react/UnlockDialog.tsx

No CLI? Copy the files by hand

  1. Open the Code tab in the preview above.
  2. Create each path listed below in your project and paste its contents in.
  3. Do the same for anything listed under “Also installs”, if present.

Props

API reference

PropTypeDefaultDescription
open *booleanWhether the dialog is visible.
value *stringCurrent input value (controlled).
onChange *(value: string) => voidCalled on every keystroke/paste.
onSubmit *() => voidCalled on Enter or the submit button.
submitting *booleanDisables the field and shows the busy label.
error *KnockCodesError | nullDrives which error message renders.
labelsKnockCodesLabelsOverrides for every user-facing string.
footerReactNodeExtra content under the form.
Notes

Accessibility

role="dialog" + aria-modal="true" + aria-labelledby pointing at the heading. Focus moves into the panel on open. Deliberately not dismissable via Escape or backdrop click — a gate you can dismiss without unlocking isn't a gate, so this omission is intentional, not a missing feature.

Customization

Composable standalone — trigger it from your own button or menu item instead of gating content directly, by controlling `open` yourself. Pass `footer` for help text or a support link under the form.

Compose with

Blocks that pair well with this one

These combine naturally with this block, whether as a shared shell, a shared session, or a common fallback.