DitherCharts

Input OTP

Updated

InputOTP draws a one-time code as pixel cells. Underneath is one real input, so SMS autofill, paste and the numeric keypad all work; pasting "123-456" keeps the digits. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

Sent to your phone

Key not found

import "@/components/dithercharts/controls.css"
import { InputOTP } from "@/components/dithercharts/input-otp"

<InputOTP
  label="Verification code"
  groups={[3, 3]}
  onComplete={(code) => verify(code)}
/>
<InputOTP label="Licence key" length={4} pattern="alphanumeric" />

Install

Controls install with DitherCharts Pro. See Installation to log in, then import controls.css once, e.g. in your root layout.

npx dithercharts add input-otp

Props

It renders a native element, so every other attribute that element takes passes through.

InputOTP props
PropTypeDefaultDescription
labelrequiredType ReactNodeDefault –The caption above the cells, and the input's accessible name.
lengthType numberDefault 6How many characters.
groupsType readonly number[]Default one runSplits the cells into runs with a pixel dash between, e.g. [3, 3].
valueType stringDefault –The code, for a controlled input; pair it with onValueChange.
defaultValueType stringDefault –The code at first, for an uncontrolled input.
onValueChangeType (value: string) => voidDefault –
onCompleteType (value: string) => voidDefault –Called once the last cell is filled.
patternType "digits" | "alphanumeric"Default –"digits" (the default, with a numeric keypad) or "alphanumeric" (letters are uppercased).
nameType stringDefault –The form field name.
disabledType booleanDefault false
classNameType stringDefault –
hintType ReactNodeDefault –Help text under the field, read after its label.
errorType ReactNodeDefault –An error under the field; it also marks the field invalid.