codefast/ui

Command Palette

Search for a command to run...

Form

Input OTP

One-time password input with slot groups and separator. Built on input-otp.

Install

pnpm add @codefast/ui

Import path

@codefast/ui/input-otp

Examples

Digits only

Pass a pattern (REGEXP_ONLY_DIGITS) to reject non-matching keystrokes.

Disabled

A non-interactive code input.

1
2
3
4
5
6

Alphanumeric

Use REGEXP_ONLY_DIGITS_AND_CHARS to accept both letters and numbers.

Controlled

Use the value and onChange props to control the input value.

Enter your one-time password.

Form

Accessible one-time password component with copy-paste functionality.

Verify your login
Enter the verification code we sent to your email address: m@example.com.

I no longer have access to this email address.

Having trouble signing in? Contact support

Four Digits

A common pattern for PIN codes. This uses the pattern={REGEXP_ONLY_DIGITS} prop.

Invalid

Use aria-invalid on the slots to show an error state.

0
0
0
0
0
0

RTL

Right-to-left layout support for languages such as Arabic and Hebrew.

Translations are AI-generated for demonstration and may be imperfect.

1
2
3
4
5
6

Separator

Use the <InputOTPSeparator /> component to add a separator between input groups.

Anatomy

How the parts compose. Copy this skeleton and fill in the slots.

import {
  InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator,
} from "@codefast/ui/input-otp";

<InputOTP maxLength={6} value={v} onChange={setV}>
  <InputOTPGroup>
    <InputOTPSlot index={0} />
  </InputOTPGroup>
</InputOTP>

API reference

Props for each part of the component. All native element props are also forwarded.

InputOTP

One-time-code input built on input-otp.

PropTypeDefaultDescription
maxLengthnumberTotal number of slots (required).
value / onChangestring / (value: string) => voidControlled value — the concatenated characters.
onComplete(value: string) => voidFires when every slot is filled.
patternstring (RegExp source)Restrict input, e.g. REGEXP_ONLY_DIGITS.

InputOTPSlot / InputOTPSeparator

PropTypeDefaultDescription
indexnumberOn a slot: its position. Wrap groups with InputOTPGroup.

Accessibility

Built to be keyboard-navigable and screen-reader friendly out of the box.

KeyFunction
Arrow+LeftMoves to the previous slot.
Arrow+RightMoves to the next slot.
BackspaceClears the current slot and steps back.
  • Renders a single hidden input — paste fills every slot at once.
  • Set autoComplete="one-time-code" so mobile keyboards offer the SMS code.
  • Always pair with a visible instruction telling users where the code came from.

Guidelines

Conventions that keep usage consistent across an app.

Do

  • Match the slot count to the real code length.
  • Group long codes (3 + 3) with a separator for readability.

Don’t

  • Don’t use OTP slots for general text — use Input.
  • Don’t block paste; many users paste the code from another app.