Skip to main content

NeoPopOTPInput

A row of digit boxes for one-time-password entry with focus highlighting, error state, mask mode, and configurable colors.

Usage

// dark mode example
import { NeoPopOTPInput } from 'neopop-rn';
import { useState } from 'react';

function Example() {
const [otp, setOtp] = useState('');

return (
<NeoPopOTPInput
length={6}
value={otp}
colorMode="dark"
onChange={setOtp}
onComplete={(value) => console.log('OTP complete:', value)}
/>
);
}
// light mode example
import { NeoPopOTPInput } from 'neopop-rn';
import { useState } from 'react';

function Example() {
const [otp, setOtp] = useState('');
const [hasError, setHasError] = useState(false);

return (
<NeoPopOTPInput
length={4}
value={otp}
mask
hasError={hasError}
colorMode="light"
colorConfig={{
borderColor: '#cccccc',
activeBorderColor: '#0d0d0d',
errorBorderColor: '#EE4D37',
backgroundColor: '#ffffff',
textColor: '#0d0d0d',
}}
onChange={setOtp}
onComplete={(value) => {
if (value !== '1234') setHasError(true);
}}
/>
);
}

Props

PropTypeDefaultDescription
lengthnumber6Number of OTP digit boxes.
valuestringCurrent OTP string; length must be ≤ length.
onChange(value: string) => voidCalled on every keystroke with the updated string.
onComplete(value: string) => voidCalled when all length boxes are filled.
maskbooleanWhen true, replaces each digit with a bullet .
hasErrorbooleanApplies errorBorderColor to all boxes.
disabledbooleanDisables all interaction.
colorConfigNeoPopOTPInputColorConfigPer-token color overrides (see colorConfig table).
colorMode'dark' | 'light'Theme mode for default colors.
containerStyleStyleProp<ViewStyle>Additional style applied to the outer row container.
boxStyleStyleProp<ViewStyle>Additional style applied to each individual digit box.
textStyleStyleProp<TextStyle>Additional style applied to each digit text.

colorConfig

KeyDescription
borderColorBox border color when inactive (not focused).
activeBorderColorBox border color when focused.
errorBorderColorBox border color when hasError is true.
backgroundColorBox background fill color.
textColorDigit text color.

Notes

  • The component uses a single hidden TextInput to capture keystrokes; focus is managed by tapping any box.
  • onComplete fires only when value.length === length; it does not fire again if the user adds more characters (the input ignores characters beyond length).
  • mask and hasError are independent; both can be active simultaneously.
  • boxStyle overrides are applied per-box, allowing individual box styling via index if needed (extend via a custom render approach).