Skip to content

OTP Input

A specialized input for One-Time Passwords with automatic focus management and numeric filtering.

import { OTPInput } from '@truongdq01/ui';
const MyForm = () => {
const [otp, setOtp] = useState('');
return (
<OTPInput
length={6}
value={otp}
onChange={setOtp}
onComplete={(value) => console.log('Ready to verify:', value)}
/>
);
};

Use the useOTPInput hook to wire up your own custom OTP cells while keeping the core logic (focus jumping, numeric-only, clipboard support).

import { useOTPInput } from '@truongdq01/ui';
import { TextInput, View } from 'react-native';
const CustomOTP = () => {
const { inputRef, getOtpProps, handlePress } = useOTPInput({
length: 4,
onChange: (val) => console.log(val),
});
return (
<View onTouchStart={handlePress}>
{/* Hidden master input */}
<TextInput
ref={inputRef}
{...getOtpProps()}
style={{ opacity: 0, position: 'absolute' }}
/>
{/* Your custom UI cells here */}
</View>
);
};
PropTypeDefaultDescription
lengthnumber6Number of OTP cells
valuestring-Current value
onChange(value: string) => void-Callback on change
onComplete(value: string) => void-Callback when all cells are filled
disabledbooleanfalseDisable input