Forms & inputs
Layout
OtpInput
A row of single-character boxes for a one-time code, with paste and auto-advance. Use it for sign-in and verification codes.
Validating a form? vael-form wires this up with a schemaInstall
import { OtpInput } from 'vael-ui'Playground
undefined
cells
Placement, behaviour and animation
numeric
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { OtpInput } from 'vael-ui'
const value = ref('')
</script>
<template>
<OtpInput aria-label="Verification code" v-model="value" />
</template>Motion New
OtpInput's motion: its parts (OtpInputPart) and states (invalid, complete, disabled, focus). Each cell plays them on its own, plus filled and current (the caret's); give a cell's values as a function to use its index. false turns it off.
<OtpInput
:motion="{ states: { invalid: { root: { scale: 1.04 } } } }"
/>| Name | Type | Description |
|---|---|---|
initialexit | rootcell | Sets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate. |
states | invalidcompletedisabledfocusfilledcurrent | Sets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid. |
enterleave | (parts, context) => animation | Animates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted. |
springdurationeasing | { damping, response } | number | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns its motion off, for an animation of your own on its exposed elements. |
Accessibility
| Key | Action |
|---|---|
| A digit | Fills the current cell and moves to the next one. |
| Backspace | Deletes the character before the caret. |
| ArrowLeftArrowRight | Moves the caret, and the highlighted cell, between cells. |
- One native text input sits over the cells and takes all typing and paste; the cells are
aria-hidden. - Inside a
Field, the label names the input. Outside one, give it anaria-labeloraria-labelledby; both go to the input, not the wrapper. - It sets
autocomplete="one-time-code", so browsers can fill a code from a text message. Withtype="alphanumeric"letters work too, and other characters are dropped. - With
mask, the cells show bullets and the input becomes a password field, so screen readers don’t read the code aloud.