InputOTP
A one-time password (OTP) input component that allows users to enter a multi-digit code.
Showcase
This is a helper message
<LnxInputOTP v-model="..." <-- Pass a reactive variable here to bind its value @update:modelValue="..." <-- Two way binding of the component > Enter something <template #error> This is an error message </template> <template #helper> This is a helper message </template> </LnxInputOTP>
v-model
string | numberBinds the value of the input to the reactive variable used as prop Default value: undefinedWhen to use
- For one-time codes sent by email or SMS, and short PINs.
- Not for passwords or for numbers of any length: use an Input.
Examples
Verification code
Six digits by default. The user can type them or paste the whole code.
We sent it to your email
vue
<LnxInputOTP v-model="code">
Verification code
<template #helper>We sent it to your email</template>
</LnxInputOTP>1
2
3
4
2
3
4
PIN
Change the number of digits with length.
vue
<LnxInputOTP v-model="pin" :length="4">
PIN
</LnxInputOTP>1
2
3
2
3
Error
The code is wrong or has expired
vue
<LnxInputOTP v-model="wrongCode" has-error>
Verification code
<template #error>The code is wrong or has expired</template>
</LnxInputOTP>1
2
3
4
2
3
4
API
Props
| Prop | Type | Description |
|---|---|---|
v-model | string | number | Binds the value of the input to the reactive variable used as prop |
is-loading | boolean | When loading, it is disabled and shows a different content Default: false |
has-error | boolean | Indicates if it should show the error slot Default: false |
length | number | Number of digits of the input Default: 6 |
Native attributes
| Attribute | Type | Description |
|---|---|---|
disabled | boolean | Disallow interaction with the input Default: false |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | string | number | Two way binding of the component |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | Label content of the input |
error | — | Message to be shown when the input has an error |
helper | — | Message to be shown below the input to add extra context |