UIComponentsReact
A one-time code typed into a row of single-character boxes.
Built on the headless OTP Field.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/input-otp.jsonIt also adds utils. The app needs its setup first: Installation.
Usage
Give InputOTP the code's length and render one InputOTPSlot per character, grouped with InputOTPGroup and split with InputOTPSeparator. Typing moves to the next slot, paste fills them all, and onValueComplete fires once every slot is filled; all of that comes from the headless OTP Field.
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from '@/components/ui/input-otp'Examples
Differences from shadcn's: the props follow Base UI's OTP Field, not the input-otp library. maxLength is length. Each InputOTPSlot is a real input that takes its position from its order, so it has no index prop. className on InputOTP styles the root, so there is no containerClassName. pattern is validationType (numeric by default) or normalizeValue. The focused slot is styled with focus-visible: in place of data-active, and the browser draws the caret, so there is no fake caret.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on OTP Field's API reference.