Skip to main content

OtpInput

Usage

function OtpInputUsage() {
return (
<View>
<OtpInput secureTextEntry onComplete={(otp) => alert(otp)} />
</View>
)
}

Modes

function OtpInputModes() {
return (
<View>
<OtpInput mode="box" />
<OtpInput mode="dash" />
</View>
)
}

Placeholder

function OtpInputPlaceholder() {
return (
<View>
<OtpInput placeholder="*" status="success" />
</View>
)
}

With Cursor

function OtpInputWithCursor() {
return (
<View>
<OtpInput withCursor />
</View>
)
}

As Pin Input

function OtpInputAsPin() {
return (
<View>
<OtpInput withCursor secureTextEntry />
</View>
)
}

Sizes

function OtpInputSizes() {
return (
<View>
<OtpInput size="small" />
<OtpInput size="medium" />
<OtpInput size="large" />
</View>
)
}

Custom

function OtpInputCustom() {
return (
<View>
<OtpInput
maxLength={6}
withAlphanumericKeyboard
boxStyle={(isFocused) => ({
borderRadius: 40,
backgroundColor: isFocused ? 'blue' : 'gold',
})}
textStyle={{
color: 'black',
fontWeight: 'bold',
}}
/>
</View>
)
}

Props

PropData TypeDefault ValueDescription
ExtendsOmit<TextInputProps, 'mode'>--Inherits properties from Omit<TextInputProps, 'mode'>
maxLengthnumber4Set the otp input length
boxStyleStyleProp<ViewStyle> | ((isFocused: boolean) => StyleProp<ViewStyle>)--Set the style for each box with isFocused prop
mode"box" | "dash"boxdifferent view based on the mode
withCursorboolean--Set it to true to enable otp cursor
withAlphanumericKeyboardboolean--Set the alphanumeric keyboard
onComplete(otp: string) => void--onComplete callback with otp input text