Skip to content

OtpCode

6-digit (or custom length) OTP code input for verification codes.

Also known as: OTP input, verification code, PIN input, 2FA code, SMS code

View in Storybook

When to use

  • Entering numeric verification codes (SMS, 2FA, email verification). Supports auto-focus, paste, and SMS autofill.

Import

tsx
import { OtpCode } from '@vacano/ui'

Usage

tsx
const [code, setCode] = useState('')

<OtpCode
  value={code}
  onChange={setCode}
/>

With Label

tsx
<OtpCode label="Verification code" />

Different Lengths

tsx
<OtpCode length={4} label="4-digit code" />
<OtpCode length={6} label="6-digit code" />
<OtpCode length={8} label="8-digit code" />

Variants

tsx
<OtpCode variant="normal" label="Normal" />
<OtpCode variant="error" label="Invalid code" />

Sizes

tsx
<OtpCode size="default" label="Default Size" />
<OtpCode size="compact" label="Compact Size" />

Disabled

tsx
<OtpCode disabled label="Disabled" value="123456" />

Features

  • Auto-focus next input on digit entry
  • Arrow key navigation (left/right)
  • Backspace deletes and moves focus back
  • Paste support (Ctrl+V)
  • Numeric input only
  • autoComplete="one-time-code" for SMS autofill

Props

PropTypeDefaultDescription
valuestring''Current OTP value
onChange(value: string) => void-Change handler
lengthnumber6Number of digits
labelstring-Label text above input
variant'normal' | 'error''normal'Visual variant
size'compact' | 'default''default'Input size
disabledbooleanfalseDisabled state
messagestring-Message text below input (error, hint)
autoFocusbooleanfalseAuto focus first input on mount
classNamestring-CSS class for root element
classnamesOtpCodeClassNames-Custom class names for inner elements
refRef<HTMLDivElement>-Ref to the root container element
data-test-idstring-Test identifier for automated testing

ClassNames

KeyDescription
containerContainer element
inputIndividual input elements
labelLabel element

Released under the MIT License.