bearnie

Input OTP

Accessible one-time password input with copy-paste support.

Installation

npx bearnie add input-otp
npx bearnie add input-otp

Usage

import {
  InputOTP,
  InputOTPGroup,
  InputOTPSlot,
  InputOTPSeparator,
} from "@/components/bearnie/input-otp"
<InputOTP maxLength={6}>
  <InputOTPGroup>
    <InputOTPSlot index={0} />
    <InputOTPSlot index={1} />
    <InputOTPSlot index={2} />
  </InputOTPGroup>
  <InputOTPSeparator />
  <InputOTPGroup>
    <InputOTPSlot index={3} />
    <InputOTPSlot index={4} />
    <InputOTPSlot index={5} />
  </InputOTPGroup>
</InputOTP>

Pattern

Use the pattern prop to define what characters are allowed in the OTP input.

Digits only (default)

Alphanumeric

Use pattern="alphanumeric" to accept both letters and numbers.

Examples

Separator

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

Disabled

Use the disabled prop to disable the input.

Invalid

Use invalid on the slots to show an error state.

Four digits

A common pattern for PIN codes.

Custom separator

You can pass custom content to the separator.

Anatomy

  • InputOTP - The main container that manages OTP state
  • InputOTPGroup - Groups slots together with connected styling
  • InputOTPSlot - Individual input slot for each digit
  • InputOTPSeparator - Visual separator between groups

Props

InputOTP

Prop Type Default Description
maxLength number required Maximum length of the OTP (number of slots)
pattern digits | alphanumeric | string digits Pattern to validate input
disabled boolean false Disables all slots
value string - Initial value
name string - Name attribute for form submission
class string - Additional CSS classes

InputOTPGroup

Prop Type Default Description
class string - Additional CSS classes

InputOTPSlot

Prop Type Default Description
index number required Index of the slot (0-based)
invalid boolean false Shows error state
class string - Additional CSS classes

InputOTPSeparator

Prop Type Default Description
class string - Additional CSS classes