Trên trang này

Trang này chưa có bản tiếng Việt, nội dung bên dưới là bản tiếng Anh. Xem trang tiếng Anh

Input OTP

Install, props and the parts Input OTP is built from.

Install

Run this in the app, after shadcn-vue init and the Beehexa theme (Button › Code):

npx shadcn-vue@latest add https://beehexa.design/r/input-otp.json

Use

<script setup lang="ts">
import { ref } from 'vue'
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp'
const code = ref('')
</script>

<template>
  <div>
    <InputOTP v-model="code" :maxlength="6" aria-label="Verification code">
      <InputOTPGroup>
        <InputOTPSlot v-for="i in 6" :key="i" :index="i - 1" />
      </InputOTPGroup>
    </InputOTP>
  </div>
</template>

Props

Part Prop Values Notes
InputOTP v-model, maxlength string, number One real input behind the boxes
InputOTP size default, lg lg: 40 px boxes
InputOTPSlot index number Which character it shows

Built on

vue-input-otp, as the shadcn-vue Input OTP. One native input holds the code, so paste and autofill (autocomplete="one-time-code") work.