Vitral 0.2.18
Form

InputOtp

One box per character of a one-time code, that moves along as you type and fills at once from a paste or autofill.

Import

main.ts
import { InputOtp } from '@vitral/vue';

Basic

Try pasting 123456.
<script setup lang="ts">import { InputOtp, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const code = ref('');const status = ref('');</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="otp-code">Verification code</Label>        <InputOtp id="otp-code" v-model="code" :length="6" integer-only @complete="status = `Checking ${$event.value}…`" />        <small style="color: var(--vt-text-muted-color)" aria-live="polite">{{ status || 'Try pasting 123456.' }}</small>    </StackPanel></template>

Masked

<script setup lang="ts">import { InputOtp, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const pin = ref('');</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="otp-pin">PIN</Label>        <InputOtp id="otp-pin" v-model="pin" mask integer-only />    </StackPanel></template>

Sizes and states

<script setup lang="ts">import { InputOtp } from '@vitral/vue';</script> <template>    <InputOtp size="small" aria-label="Small" />    <InputOtp size="large" variant="filled" aria-label="Large, filled" />    <InputOtp invalid aria-label="Invalid" model-value="12" />    <InputOtp disabled aria-label="Disabled" model-value="1234" /></template>

API

Read from packages/vue/src/components/InputOtp/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
length numberHow many characters the code has. Defaults to 4.
integerOnly booleanAccept digits only, and ask for the numeric keyboard.
mask booleanHide the characters as a password box does.
size Size—
variant InputVariantDefaults to the plugin's `inputVariant`.
invalid boolean—
disabled boolean—
readonly boolean—

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
change event: { originalEvent: Event; value: string }—
complete event: { originalEvent: Event; value: string }Every box holds a character.
focus event: FocusEvent—
blur event: FocusEvent—

Slots

NameSlot propsDescription
default (props: { index: numberReplaces a box. The events wire it up; `attrs` carries its name and state.
value string—
attrs Record<string, unknown>—
events { input: (event: Event) => void; keydown: (event: KeyboardEvent) => void; paste: (event: ClipboardEvent) => void; focus: (event: FocusEvent) => void }—