nessra uinessra ui

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

Loading...
"use client"

import {

Installation

pnpmnpmyarnbun
pnpm dlx shadcn@latest add https://nessra-ui.vercel.app/r/input-otp.json

Usage

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

Examples

With Separator

Use InputOTPSeparator to add a visual separator between groups.

Loading...
"use client"

import {

Controlled

Control the input value with value and onChange.

Loading...
"use client"

import * as React from "react"

Pattern

Use the pattern prop to restrict input to specific characters.

Loading...
"use client"

import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp"

API Reference

InputOTP

The root component that manages the OTP input state.

PropTypeDefaultDescription
maxLengthnumber-Maximum number of characters
valuestring-Controlled value
onChange(value: string) => void-Called when the value changes
patternstring | RegExpREGEXP_ONLY_DIGITSPattern to validate input
disabledbooleanfalseDisable the input
autoFocusbooleanfalseAuto focus on mount

InputOTPGroup

Groups slots together visually.

InputOTPSlot

Individual character slot.

PropTypeDefaultDescription
indexnumber-The index of the slot (0-based)

InputOTPSeparator

Visual separator between groups.

Credits

Built on top of input-otp by @guilhermerodz.