Form

OTP Input

One-time-code input with auto-advance, paste-to-fill, masking and grouping — sizes and states, in React (@bpdm/ui) and Angular (@bpdm/ng).

The OTP Input is a one-time-code field — one box per character, with auto-advance, backspace-to-previous, arrow-key navigation, and paste-to-fill (paste the whole code into any box). The value is a plain string; it runs controlled (value + onValueChange) or uncontrolled (defaultValue). In React it's <InputOtp>; in Angular it's <bpdm-input-otp>.

Usage

Set the number of boxes with length. Add integerOnly to accept digits only (typical for SMS / authenticator codes).

verify.tsx
import { InputOtp } from '@bpdm/ui/input-otp';

export function Verify() {
  return <InputOtp length={6} integerOnly aria-label="Verification code" />;
}

For a controlled field, pass value and onValueChange — and use onComplete to fire your check the moment every box is filled (autoFocus puts the cursor in the first box on mount):

controlled.tsx
import { useState } from 'react';
import { InputOtp } from '@bpdm/ui/input-otp';

export function Controlled({ onVerify }: { onVerify: (code: string) => void }) {
  const [code, setCode] = useState('');
  return (
    <InputOtp
      length={6}
      integerOnly
      autoFocus
      value={code}
      onValueChange={setCode}
      onComplete={onVerify}
    />
  );
}

Masked (PIN)

For a PIN or other secret code, add mask to render dots instead of the characters. The real value is still reported through onValueChange.

pin.tsx
import { InputOtp } from '@bpdm/ui/input-otp';

export function Pin() {
  return <InputOtp length={4} mask integerOnly aria-label="PIN" />;
}

Grouping

grouped splits the boxes into even halves with a separator; groupSize groups every N boxes instead. Set the separator character with separator (default −).

grouped.tsx
import { InputOtp } from '@bpdm/ui/input-otp';

export function Grouped() {
  return (
    <div className="flex flex-col items-center gap-4">
      <InputOtp length={6} grouped separator="−" integerOnly />
      <InputOtp length={9} groupSize={3} separator="−" integerOnly />
    </div>
  );
}

Sizes

Three cell sizes — sm, md (default), and lg.

sizes.tsx
import { InputOtp } from '@bpdm/ui/input-otp';

export function Sizes() {
  return (
    <div className="flex flex-col items-center gap-4">
      <InputOtp length={4} size="sm" integerOnly />
      <InputOtp length={4} size="md" integerOnly />
      <InputOtp length={4} size="lg" integerOnly />
    </div>
  );
}

States

Disable the whole field while a request is in flight or the code is locked.

states.tsx
import { InputOtp } from '@bpdm/ui/input-otp';

export function States() {
  return <InputOtp length={6} disabled defaultValue="123456" />;
}

Per-slot styling

className (or Angular class) styles the group as a whole. To restyle individual parts without reaching into the internal data-bpdm-slot elements from CSS, pass a classNames object — one key per slot: root (the outer group wrapper), slot (each character cell) and input (the hidden form input emitted when name is set). Each entry merges with the component's own classes, so you override only what you name.

input-otp-slots.tsx
import { InputOtp } from '@bpdm/ui/input-otp';

export function StyledCode() {
  return (
    <InputOtp
      length={6}
      integerOnly
      name="code"
      aria-label="Verification code"
      classNames={{
        root: 'gap-1.5',
        slot: 'rounded-lg border-2 font-mono',
        input: 'sr-only',
      }}
    />
  );
}

API

InputOtp / bpdm-input-otp

The value is a plain string of the entered characters ("" when empty).

PropTypeDefaultDescription
lengthnumber6Number of cells.
valuestring—Controlled value. React: pair with onValueChange. Angular: two-way [(value)].
defaultValuestring""Uncontrolled initial value.
onValueChange (React)(value: string) => void—Called with the joined value on every change.
onComplete (React) / (complete) (Angular)(value: string) => void—Fired once every cell is filled — handy for auto-submit.
autoFocusbooleanfalseFocus the first cell on mount.
maskbooleanfalseHide characters (one-time PINs).
integerOnlybooleanfalseRestrict input to digits 0–9 (also sets inputmode="numeric").
sizesm | md | lgmdCell size.
groupSizenumber—Connect cells into fixed groups of this size (last = remainder).
groupedbooleanfalseAuto-group into two balanced segments. Ignored if groupSize is set.
separatorReactNode (React) / string (Angular)−Node/character shown between groups.
disabledbooleanfalseDisable every cell.
namestring—Emits the joined value under this name via a hidden input for native form submission.
idstring—Group id (for label association / testing).
aria-labelstring"One-time code"Accessible name for the group.
aria-describedbystring—IDs of describing elements (help / error text).
cellLabel(index, length) => stringCharacter N of MPer-cell screen-reader label — override for i18n. See Internationalization.
className (React) / class (Angular)string—Extra classes on the group.
classNamesInputOtpClassNames—Per-slot class overrides: { root, slot, input }. Each merges with the component's own classes.

InputOtpClassNames: { root, slot, input }.

Accessibility

  • The cells sit in a role="group" named by aria-label (default One-time code) — give it a meaningful name such as Verification code. Link help or error text with aria-describedby.
  • Each cell is a labelled <input> (Character N of M) with full keyboard support: type to auto-advance, Backspace to clear and step back, ←/→ to move between cells, and paste-to-fill from any cell.
  • The first cell carries autocomplete="one-time-code", so iOS/Android offer to fill an SMS code; integerOnly also sets inputmode="numeric" for a numeric keypad.
  • mask hides characters with -webkit-text-security while keeping a normal text input (and tells password managers to ignore it), so the real value is still reported to onValueChange.
  • The group separator is decorative (aria-hidden), so screen readers read the code as one field.
  • Setting name emits the joined value through a hidden input, so the field submits with a native <form>.

Internationalization

  • The group name (aria-label) and the per-cell label (cellLabel, default Character N of M) are translatable — see Translating labels.
  • RTL-safe: the connected-cell rounding uses logical properties and the arrow keys follow the visual order (ArrowLeft advances in dir="rtl"); autocomplete="one-time-code" still triggers SMS autofill.

On this page