Captain UI

Code input

A one-time code in six wells. Paste fills every cell at once, the caret glides to the next one as you type, a wrong code shakes and clears.

npx shadcn@latest add https://captain-ui.vercel.app/r/code-input.json

Approve the deploy to production

Enter the code sent to the phone ending 4821. This demo accepts 204816.

Usage

import { CodeInput } from "@/components/ui/code-input"

<CodeInput onComplete={async (code) => (await verify(code)).ok} />

Props

PropTypeDefaultWhat it does
lengthnumber6How many digits.
valuestringControlled value.
defaultValuestring""Initial value when uncontrolled.
onValueChange(value: string) => voidCalled on every keystroke or paste.
onComplete(code: string) => boolean | void | Promise<boolean | void>Called when full. false shakes and clears, true shows success; a promise shows checking until it settles.
status"idle" | "checking" | "error" | "success"Drive the state yourself instead.
groupsnumber[][3, 3]Cells per group; groups get a wider gap.
autoFocusbooleanFocus on mount.
disabledbooleanDims and ignores input.

Keyboard

0–9
Type into the next cell
Backspace
Clear the last cell
Cmd/Ctrl + V
Paste the whole code

Accessibility

  • One real input with autocomplete=one-time-code, so SMS codes autofill on iOS and Android.
  • The status (checking, wrong, accepted) is announced through a polite live region.
  • aria-invalid is set while a wrong code is shown.