Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.
Six digits
Paste works: the whole code fills in.
We sent a 6-digit code to [email protected].
InputOTPBasic.vue
<script setup lang="ts">
import { ref } from 'vue'
import { REGEXP_ONLY_DIGITS } from 'vue-input-otp'
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp'
const code = ref('')
</script>
<template>
<div class="grid gap-(--bh-space-100)">
<label for="sign-in-code" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Sign-in code</label>
<InputOTP
id="sign-in-code"
v-slot="{ slots }"
v-model="code"
:maxlength="6"
:pattern="REGEXP_ONLY_DIGITS"
autocomplete="one-time-code"
aria-describedby="sign-in-code-hint"
>
<InputOTPGroup>
<InputOTPSlot v-for="(_, index) in slots" :key="index" :index="index" />
</InputOTPGroup>
</InputOTP>
<p id="sign-in-code-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">We sent a 6-digit code to [email protected].</p>
</div>
</template>In groups
A separator splits the code into groups that are easier to read.
InputOTPGroups.vue
<script setup lang="ts">
import { ref } from 'vue'
import { REGEXP_ONLY_DIGITS_AND_CHARS } from 'vue-input-otp'
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from '@/components/ui/input-otp'
const code = ref('')
</script>
<template>
<div class="grid gap-(--bh-space-100)">
<label for="recovery-code" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Recovery code</label>
<InputOTP
id="recovery-code"
v-model="code"
:maxlength="6"
:pattern="REGEXP_ONLY_DIGITS_AND_CHARS"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
</div>
</template>Checking the code
The code is checked once every box is filled; a wrong code shows an error.
1
2
3
4
5
6
That code is not right. Check the latest email and try again.
Available after the ERP sends a code.
InputOTPStates.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { REGEXP_ONLY_DIGITS } from 'vue-input-otp'
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp'
// The code is checked once all 6 digits are in. Type any other code to clear the error.
const code = ref('123456')
const wrong = computed(() => code.value === '123456')
</script>
<template>
<div class="grid gap-(--bh-space-300)">
<div class="grid gap-(--bh-space-100)">
<label for="checked-code" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Verification code</label>
<InputOTP
id="checked-code"
v-model="code"
:maxlength="6"
:pattern="REGEXP_ONLY_DIGITS"
:aria-invalid="wrong"
aria-describedby="checked-code-error"
>
<InputOTPGroup>
<InputOTPSlot v-for="index in 6" :key="index" :index="index - 1" />
</InputOTPGroup>
</InputOTP>
<p v-if="wrong" id="checked-code-error" class="m-0 text-(--bh-color-text-danger) [font:var(--bh-font-body-small)]">That code is not right. Check the latest email and try again.</p>
</div>
<div class="grid gap-(--bh-space-100)">
<label for="waiting-code" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Code from the ERP</label>
<InputOTP id="waiting-code" :maxlength="6" disabled aria-describedby="waiting-code-hint">
<InputOTPGroup>
<InputOTPSlot v-for="index in 6" :key="index" :index="index - 1" />
</InputOTPGroup>
</InputOTP>
<p id="waiting-code-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">Available after the ERP sends a code.</p>
</div>
</div>
</template>Large
size="lg" makes every box 40 px (size.control.large), for sign-in and onboarding pages.
We sent a 6-digit code to [email protected].
InputOTPLarge.vue
<script setup lang="ts">
import { ref } from 'vue'
import { REGEXP_ONLY_DIGITS } from 'vue-input-otp'
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp'
const code = ref('')
</script>
<template>
<div class="grid gap-(--bh-space-100)">
<label for="large-code" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Sign-in code</label>
<InputOTP
id="large-code"
v-slot="{ slots }"
v-model="code"
:maxlength="6"
size="lg"
:pattern="REGEXP_ONLY_DIGITS"
autocomplete="one-time-code"
aria-describedby="large-code-hint"
>
<InputOTPGroup>
<InputOTPSlot v-for="(_, index) in slots" :key="index" :index="index" />
</InputOTPGroup>
</InputOTP>
<p id="large-code-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">We sent a 6-digit code to [email protected].</p>
</div>
</template>