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/ui"
<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

PropTypeDefaultDescription
maxLengthnumberrequiredMaximum length of the OTP (number of slots)
patterndigits | alphanumeric | stringdigitsPattern to validate input
disabledbooleanfalseDisables all slots
valuestring-Initial value
namestring-Name attribute for form submission
classstring-Additional CSS classes

InputOTPGroup

PropTypeDefaultDescription
classstring-Additional CSS classes

InputOTPSlot

PropTypeDefaultDescription
indexnumberrequiredIndex of the slot (0-based)
invalidbooleanfalseShows error state
classstring-Additional CSS classes

InputOTPSeparator

PropTypeDefaultDescription
classstring-Additional CSS classes