Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createOtp

Manage a fixed-length one-time-password or verification-code value with pattern-gated entry, length-based completion detection, and a decisional async hook. Headless — your component owns rendering, focus, and event wiring.

Usage

ts
import { createOtp } from '@vuetify/v0'

const otp = createOtp({
  length: 6,
  pattern: 'numeric',
  onComplete: async value => {
    const ok = await verify(value)
    return ok // false clears the value and surfaces an error
  },
})

otp.write(0, '4')          // single character at a position
otp.distribute('123456')   // distributes filtered characters
otp.value.value            // '412345' joined string
otp.isComplete.value       // true when length reached and all chars valid
otp.accepts('a')           // false under 'numeric'
otp.clear()

Architecture

Layer 2 orchestrator. Aggregates createInput for validation, dirty tracking, and ARIA wiring. No registry, no focus traversal, no observers — rendering, per-element refs, and keyboard wiring are the consumer’s responsibility.

Reactivity

PropertyTypeReactiveDescription
valueReadonly<Ref<string>>Joined OTP string. Readonly — mutate via the helpers below.
lengthReadonly<Ref<number>>Target character count from the length option.
inputInputContext<string>Underlying createInput surface — ARIA IDs, errors, validation, focus/touched.
isCompleteReadonly<Ref<boolean>>true when value reaches length and every character passes accepts. Fires onComplete on the false → true edge.
write(index, char)(index: number, char: string) => voidWrites one character at index. Empty char truncates to value.slice(0, index) (Backspace mental model). Multi-character char is reduced to the first character — use distribute for multi-character input.
distribute(text, index?)(text: string, index?: number) => numberFilters text through accepts, splices at index (default 0), clips to length. Returns the count consumed so consumers can advance focus.
clear()() => voidEmpties the joined value.
fill(text)(text: string) => voidReplaces the joined value (filtered + clipped).
accepts(char)(char: string) => booleanPattern test, exposed so consumers can guard beforeinput.

Every helper is gated on the configured disabled and readonly options, and on the internal pending state while an async onComplete is in flight.

Patterns

PatternMatches
'numeric'[0-9]
'alphanumeric'[a-zA-Z0-9]
'alphabetic'[a-zA-Z]
RegExpCustom; tested per character

accepts(char) is the single point of truth and is reactive through MaybeRefOrGetter — toggle modes at runtime and every helper respects the new pattern on the next call.

Examples

FAQ

API Reference

The following API details are for the createOtp composable.
Was this page helpful?

Ctrl+/