On this page

Pin input

Live examples of Pin input, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

Four digits

Focus moves to the next box as people type.

Staff PIN for the shop counter

4 digits.

PinInputBasic.vue
<script setup lang="ts">
import { ref } from 'vue'
import { PinInput, PinInputGroup, PinInputSlot } from '@/components/ui/pin-input'

const pin = ref<string[]>([])
const done = ref(false)
</script>

<template>
  <div class="grid gap-(--bh-space-100)">
    <span id="staff-pin-label" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Staff PIN for the shop counter</span>
    <PinInput
      id="staff-pin"
      v-model="pin"
      mask
      placeholder="○"
      role="group"
      aria-labelledby="staff-pin-label"
      @complete="done = true"
    >
      <PinInputGroup>
        <PinInputSlot v-for="(_, index) in 4" :key="index" :index="index" :aria-label="`Digit ${index + 1} of 4`" />
      </PinInputGroup>
    </PinInput>
    <p class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]" aria-live="polite">{{ done ? 'PIN entered.' : '4 digits.' }}</p>
  </div>
</template>

In groups

A separator splits a longer code.

Pairing code shown on the device
PinInputGroups.vue
<script setup lang="ts">
import { ref } from 'vue'
import { PinInput, PinInputGroup, PinInputSeparator, PinInputSlot } from '@/components/ui/pin-input'

const code = ref<string[]>([])
</script>

<template>
  <div class="grid gap-(--bh-space-100)">
    <span id="pairing-code-label" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Pairing code shown on the device</span>
    <PinInput id="pairing-code" v-model="code" placeholder="○" role="group" aria-labelledby="pairing-code-label">
      <PinInputGroup>
        <PinInputSlot v-for="index in 3" :key="index" :index="index - 1" :aria-label="`Character ${index} of 6`" />
      </PinInputGroup>
      <PinInputSeparator />
      <PinInputGroup>
        <PinInputSlot v-for="index in 3" :key="index" :index="index + 2" :aria-label="`Character ${index + 3} of 6`" />
      </PinInputGroup>
    </PinInput>
  </div>
</template>