OTPInput

OTPInput is an animated OTP input component for React Native and React, from the dissolve library. One time code boxes, verify sweep, success tint, shake and dust on reject.

One time code input. A hidden field (SMS autofill, paste) drives the boxes, the active box blinks a calm caret and each digit lands crisply. A full code is checked: the boxes turn green, or the row shakes and the digits blow away as dust before the input clears and asks again.

Install

React Native

Install the engine once per app and wrap the root layout in <DissolveProvider> (see Installation), then copy the component into components/dissolve:

npx expo install dissolve-ui @shopify/react-native-skia react-native-reanimated react-native-worklets react-native-gesture-handler expo-haptics
npx dissolve-ui add otp-input --native
npx shadcn@latest add https://dissolve.rselmi.com/r/native/otp-input.json

React

Needs React 19 and react-dom, nothing else: no engine, no provider, no Tailwind. Works in the Next.js App Router.

npx dissolve-ui add otp-input --web
npx shadcn@latest add https://dissolve.rselmi.com/r/otp-input.json

Usage

OTPInput.tsx (React Native)
import { OTPInput } from '@/components/dissolve/otp-input';

<OTPInput
  autoFocus
  onComplete={async (code) => (await api.verify(code)).ok}
/>
OTPInput.tsx (React)
import { OTPInput } from '@/components/dissolve/otp-input';

<OTPInput
  autoFocus
  onComplete={async (code) => (await api.verify(code)).ok}
/>

Props

PropTypeDefaultDescription
lengthnumber6Number of digits.
valuestringControlled value. Leave undefined to let the input own its state.
onChange(code: string) => voidCalled on every change.
onComplete(code: string) => boolean | void | PromiseRuns once every box is filled. True shows the success state, false rejects: the row shakes, the digits turn to dust and the input clears. Nothing leaves the code in place.
autoFocusbooleanfalseFocus on mount.
heightnumber56Box height. Box width follows the available space unless boxWidth is set.
boxWidthnumberFixed box width.
gapnumber8Space between boxes.
fontSizenumber26Digit size.
radiusnumber14Box corner radius.
blurOnSuccessbooleantrueClose the keyboard once the code is accepted.
hapticsbooleantrueSuccess and error notifications.
classNamestringRoot: margins, width.
boxClassNamestringEvery box: shadow, extra layout. Box colors are animated from the surface, border, foreground, success and danger tokens.
digitClassNamestring'font-semibold'Digits: weight, family. Their color is animated from the tokens.

Source

Previous: SlideToConfirm · Next: NumberTicker · All components

dissolve is MIT licensed. Source on GitHub, package on npm. This page as markdown. For AI agents: llms.txt.