Pin Input
newCheck your SMS. We'll wait. One box per character, for one-time codes and PINs.
Enter the six digits we sent you.
Open Props in the corner of the example to try variant, size and disabled.
The five text control variants, the same as on Input.
Slots run from 28px at xs to 48px at xl, the heights of the matching inputs, and the type scales with them.
Installation
Usage
<script setup lang="ts">
import { PinInput, PinInputGroup, PinInputSlot } from '@/components/ui/pin-input'
const code = ref<string[]>([])
</script>
<template>
<PinInput v-model="code" aria-label="One-time code">
<PinInputGroup>
<PinInputSlot v-for="index in [0, 1, 2, 3]" :key="index" :index="index" />
</PinInputGroup>
</PinInput>
</template>
Each PinInputSlot is a square box in Input's variants and sizes. v-model is an array, one character per slot.
Typing jumps to the next slot, Backspace goes back, and pasting a code fills them all. Once every slot is filled, complete fires with the value.
Phones offer the code from the SMS out of the box (otp is on by default).
Set name, and the joined code submits with the form. Give it an aria-label, or put it in a Field.
Examples
Mask
mask hides the characters like a password field; placeholder shows a character in every empty slot. type="number" accepts digits only and brings up the numeric keyboard on phones.
In a field
Label, description and error come from the field; invalid marks every slot.
Four digits from the authenticator app.
API Reference
Every part accepts class, merged over its base classes.
PinInput
| Prop | Default | Type and description |
|---|---|---|
| modelValue | — | PinInputValue<Type> | nullThe characters, one per slot, bound with |
| defaultValue | — | PinInputValue<Type>The starting characters when |
| placeholder | — | stringA character shown in every empty slot. |
| mask | — | booleanHides the characters like a password field. |
| otp | true | booleanLets phones offer a code from a message and marks the boxes |
| type | — | Type
|
| dir | — | DirectionReading direction. In |
| disabled | — | booleanDisables every slot. Also set by a disabled field. |
| id | — | stringOverrides the |
| asChild | — | booleanRender the single child instead of a wrapper, merging the root's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| name | — | stringSubmits the joined characters with the form under this name. |
| required | — | booleanMarks the hidden form input required. Also set by a required field. |
| variant | "outline" | "outline" | "soft" | "filled" | "ghost" | "subtle"The text control look, shared with |
| size | "md" | "xs" | "sm" | "md" | "lg" | "xl"The slot size, from 28px at |
| Event | Payload and description |
|---|---|
| update:modelValue | [value: PinInputValue<Type>]Fires as characters are typed, pasted or deleted. |
| complete | [value: PinInputValue<Type>]Fires once every slot has a character, with the full value. |
| Slot | Scope and description |
|---|---|
| default | {}The groups, slots and separators. Receives |
PinInputGroup
| Slot | Scope and description |
|---|---|
| default | {}A run of slots, spaced like the root. |
PinInputSlot
| Prop | Default | Type and description |
|---|---|---|
| index* | — | numberWhich character this slot holds, from 0. |
| disabled | — | booleanDisables this slot alone. |
| asChild | — | booleanRender the single child instead of a wrapper, merging the slot's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
PinInputSeparator
| Slot | Scope and description |
|---|---|
| default | {}Replaces the dash between two groups. |
Props
- modelValue
PinInputValue<Type> | nullThe characters, one per slot, bound withv-model. Strings, or numbers withtype="number".- defaultValue
PinInputValue<Type>The starting characters whenv-modelis not used.- placeholder
stringA character shown in every empty slot.- mask
booleanHides the characters like a password field.- otp
true booleanLets phones offer a code from a message and marks the boxesautocomplete="one-time-code". On by default.- type
Typetextaccepts any character;numberonly digits, and brings up the numeric keyboard on phones.- dir
DirectionReading direction. Inrtlthe slots fill from the right.- disabled
booleanDisables every slot. Also set by a disabled field.- id
stringOverrides theidtaken from a surrounding field. It lands on the hidden form input, so the field's label focuses the first slot.- asChild
booleanRender the single child instead of a wrapper, merging the root's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.- name
stringSubmits the joined characters with the form under this name.- required
booleanMarks the hidden form input required. Also set by a required field.- variant
"outline" "outline" | "soft" | "filled" | "ghost" | "subtle"The text control look, shared withInput:outline,soft,filled,ghostorsubtle.- size
"md" "xs" | "sm" | "md" | "lg" | "xl"The slot size, from 28px atxsto 48px atxl; the type scales with it.
Emits
- update:modelValue
[value: PinInputValue<Type>]Fires as characters are typed, pasted or deleted.- complete
[value: PinInputValue<Type>]Fires once every slot has a character, with the full value.
Slots
- default
{}The groups, slots and separators. ReceivesmodelValue.
Slots
- default
{}A run of slots, spaced like the root.
Props
- index*
numberWhich character this slot holds, from 0.- disabled
booleanDisables this slot alone.- asChild
booleanRender the single child instead of a wrapper, merging the slot's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}Replaces the dash between two groups.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| pin-input | data-variant, data-size, data-complete, data-disabled | The root, a role="group", holding the hidden form input. |
| pin-input-group | — | A run of slots. |
| pin-input-slot | data-complete, data-disabled, aria-invalid | One text box. |
| pin-input-separator | — | The dash between groups, hidden from screen readers. |
Keyboard
| Key | Action |
|---|---|
| ArrowLeft / ArrowRight | Moves focus to the previous or next slot. |
| Backspace | Clears the slot, or moves back and clears the previous one when empty. |
| Delete | Clears the slot. |
| Home / End | Moves focus to the first or last slot. |