---
title: "OTP Input"
description: "Digits roll into slots, with SMS autofill."
documentation: "https://beui.dev/react-native/otp-input"
markdown: "https://beui.dev/react-native/otp-input.md"
---

# OTP Input

> Digits roll into slots, with SMS autofill.

React Native component for Expo, from beUI Native. Group: Forms. Variants: 1.

## Install

Set up beUI Native once per app first: https://beui.dev/docs/native-setup.md

```bash
npx beui-native add otp-input
```

Or copy the source by hand and install its libraries:

```bash
npx expo install react-native-reanimated react-native-worklets
npm install uniwind tailwindcss
```

## Links

- Source: https://github.com/starc007/beui-native/tree/main/src/components/otp-input
- Registry JSON with every file: https://beui.dev/native/r/otp-input
- Open in Expo Go: exp://u.expo.dev/93a3a95c-6dc2-4adb-b57c-efbecf859f25/--/otp-input?runtime-version=exposdk%3A58.0.0&channel-name=production
- Web version: https://beui.dev/components/blocks/otp-input.md

## README

### OTP Input

Native port of [beUI OTP Input](https://beui.dev/components/blocks/otp-input). A one-time-code field whose digits roll into their slots, with an error shake and a check that draws itself on success.

```tsx
import { OTPInput } from "./src";

<OTPInput
  label="Verification code"
  hint="We sent a code to your phone."
  errorMessage="Wrong code, try again."
  successMessage="Verified."
  value={code}
  status={status}
  onChangeText={setCode}
  onComplete={verify}
/>
```

- **Slots:** `length` slots (6 by default), 48 by 56 points each. Each new digit rolls up into its slot over 220 ms, and a deleted digit rolls out upward. `mask` shows dots instead of digits.
- **Caret:** the active slot shows a blinking caret and a stronger border. Slot borders fade between empty, filled, active, error and success colours.
- **Status:** `status="error"` shakes the slots and turns them red. `status="success"` turns them green and springs in a check that draws itself beside the slots. Each status message is announced to screen readers.
- **Input:** a transparent native `TextInput` covers the slots and owns focus, the number pad, paste and SMS autofill (`oneTimeCode` on iOS, `sms-otp` on Android). It only accepts digits. `onComplete` fires when the last slot fills.
- **State:** pass `value` with `onChangeText` to control it, or `defaultValue` to let it manage itself.
- **Keyboard:** the number pad follows the app's light or dark theme on iOS (override with `keyboardAppearance`). `blurOnComplete` dismisses the keyboard once the last slot fills.
- **Accessibility:** screen readers see one field named by `label` (or "One-time passcode"), with the current message as its hint. The drawn slots are hidden from them.
- **Reduced motion:** when the system asks for it, or `disableAnimation` is set, digits and colours change instantly, the caret stays solid, and nothing shakes.

Unlike the web version, editing always happens at the end of the code: backspace removes the last digit and typing appends. The web version lets you place the caret in a middle slot with a mouse or the arrow keys, which touch keyboards don't offer.

Copy this directory, `hooks/use-presence.ts`, `hooks/use-reduced-motion.ts`, `hooks/use-shake.ts`, `primitives/drawn-path.tsx`, `styles/motion.ts`, and the semantic tokens in `styles/theme.css`.
