Back to Element Plus

InputOtp

docs/en-US/component/input-otp.md

2.14.06.0 KB
Original Source

InputOtp ^(beta)

Used to enter a one-time password (OTP).

Basic Usage

:::demo

input-otp/basic

:::

Custom Length

The length of the input fields can be customized by setting the length prop.

:::demo

input-otp/custom-length

:::

Types

There are three types available: outlined (default), filled, and underlined.

:::demo

input-otp/types

:::

Sizes

There are three sizes available: large, default, and small.

:::demo

input-otp/sizes

:::

Disabled & Readonly

Disabled and readonly states are supported.

:::demo

input-otp/disabled

:::

Mask

Use the mask prop to hide the input characters.

:::demo

input-otp/mask

:::

Separator

Customize the separator between OTP fields.

:::demo

input-otp/separator

:::

Custom Validation

Set the validator prop to validate the input character, and use inputmode to specify the keyboard type.

:::demo

input-otp/validator

:::

API

Attributes

NameDescriptionTypeDefault
model-value / v-modelThe value of the OTP fields. Since numbers must not have leading zeros, modelValue is allowed to be a number only during initialization.^[string] / ^[number]undefined
lengthThe OTP fields length^[number]6
validatorCustom validator function^[Function](char: string, index: number) => boolean() => true
inputmodeNative inputmode attribute^[string]
typeThe type of the OTP fields^[enum]'outlined' | 'filled' | 'underlined''outlined'
sizeThe size of the OTP fields^[enum]'large' | 'default' | 'small''default'
maskWhether to enable password mode^[boolean]
disabledWhether the OTP fields are disabled^[boolean]undefined
separatorThe separator between OTP fields^[string] / ^[VNode] / ^[Function]() => string | VNode
validate-eventWhether to trigger form validation^[boolean]true
readonlySame as readonly in native input^[boolean]false
idNative id attribute^[string]
aria-label ^(a11y)Native aria-label attribute^[string]

Events

NameDescriptionType
update:modelValueTriggers when value updates^[Function](value: string) => void
changeTriggers when the value changes after input blur^[Function](value: string) => void
finishFires when all fields have been filled^[Function](value: string) => void
focusTriggers when input is focused^[Function](event: FocusEvent) => void
blurTriggers when input is blurred^[Function](event: FocusEvent) => void

Slots

NameDescriptionType
separatorThe separator between OTP fields^[object]{ index: number }

Exposes

NameDescriptionType
inputRefsHTML input elements array^[object]Ref<(HTMLInputElement | undefined)[]>
focusFocus an OTP input field^[Function](index?: number) => void
blurBlur the focused OTP input field^[Function]() => void