OTP Input

A small one-time password input inspired by shadcn-vue, simplified for Nuxt auto-import and direct output events.

Installation

npx alixan-ui-nuxt add otp

Usage

Value: -

<script setup lang="ts">
const code = ref('')

const verify = (value: string) => {
  console.log('submit', value)
}
</script>

<template>
  <OtpInput v-model="code" :length="6" @submit="verify" />
</template>

Length

<template>
  <div class="grid gap-4">
    <OtpInput :length="4" />
    <OtpInput :length="8" />
  </div>
</template>

API Reference

PropTypeDefaultDescription
modelValuestring''OTP value used by v-model.
length4 | 5 | 6 | 7 | 86Number of OTP digits. Values are clamped between 4 and 8.
EventTypeDescription
@change(value: string) => voidEmitted on every OTP value change.
@submit(value: string) => voidEmitted when the OTP value reaches the selected length.