WlInputOtp
Limits
Type or paste the code as one field. FormData receives a string with leading zeros. The application verifies the code.
Full example
<script setup lang="ts">
import { WlButton, WlField, WlInputOtp } from "legato-ui";
import { ref } from "vue";
const code = ref("");
const submitted = ref("");
function submit(event: Event): void {
if (event.currentTarget instanceof HTMLFormElement) {
submitted.value = String(new FormData(event.currentTarget).get("code") ?? "");
}
}
</script>
<template>
<form class="wl-stack" data-space="md" @submit.prevent="submit">
<WlField v-slot="{ id, labelId }" label="Verification code">
<WlInputOtp
:id="id"
v-model="code"
name="code"
:length="6"
:aria-labelledby="labelId"
/>
</WlField>
<div><WlButton type="submit">{{ "Send code" }}</WlButton></div>
<output v-if="submitted" aria-label="Verification code">{{ submitted }}</output>
</form>
</template>States
Full example
<script setup lang="ts">
import { WlButton, WlField, WlInputOtp } from "legato-ui";
import { ref } from "vue";
const code = ref("");
const submitted = ref("");
function submit(event: Event): void {
if (event.currentTarget instanceof HTMLFormElement) {
submitted.value = String(new FormData(event.currentTarget).get("code") ?? "");
}
}
</script>
<template>
<form class="wl-stack" data-space="md" @submit.prevent="submit">
<WlField v-slot="{ id, labelId }" label="Verification code">
<WlInputOtp
:id="id"
v-model="code"
name="code"
:length="6"
:aria-labelledby="labelId"
/>
</WlField>
<div><WlButton type="submit">{{ "Send code" }}</WlButton></div>
<output v-if="submitted" aria-label="Verification code">{{ submitted }}</output>
</form>
</template>React to a complete code
The complete event sends the whole code as a string, including its leading zeros.
Full example
<script setup lang="ts">
import { WlField, WlInputOtp } from "legato-ui";
import { ref } from "vue";
const code = ref("");
const completed = ref("");
</script>
<template>
<div class="wl-stack" data-space="sm">
<WlField
v-slot="{ id, ariaDescribedby }"
label="Verification code"
hint="Type or paste four digits, such as 0042."
>
<WlInputOtp
:id="id"
v-model="code"
:length="4"
:aria-describedby="ariaDescribedby"
@complete="completed = $event"
/>
</WlField>
<output v-if="completed" class="wl-text-small" aria-label="Last complete code">
{{ "Last complete code" }} <code>{{ completed }}</code>
</output>
</div>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model: stringCode as a string, including leading zeros.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
length | number | 6 | Number of digits in the code. |
disabled | boolean | Not set | Prevent entry and exclude the value from form submission. |
invalid | boolean | Not set | Expose an invalid state on the native input. |
pt | WlPt< | Not set | Attributes for the wrapper, native input and visual cells. |
Events
| Event | Payload | When emitted |
|---|---|---|
complete | [code: string] | Emitted after user input completes the required number of digits. |
update:modelValue | string | The updated code after editing, which may be incomplete. |
Slots
No public slots.
Pass-through: pt
Sections WlInputOtp are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-input-otp | Main element of the component. |
input | input.wl-input-otp__input | Native single-value input. |
cell | span.wl-input-otp__cell | A visual code cell. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Type or paste the code as one field. FormData receives a string with leading zeros. The application verifies the code.
- Give the whole input a single label, such as Verification code. The visible cells belong to that input.
- Associate an error or hint with the native input using WlField or aria-describedby.
Keyboard and application responsibilities
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.