Pin Input

new

Check your SMS. We'll wait. One box per character, for one-time codes and PINs.

Demo

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.

Mask

In a field

Label, description and error come from the field; invalid marks every slot.

In a field

Four digits from the authenticator app.

API Reference

Every part accepts class, merged over its base classes.

Data attributes

data-slotAttributesDescription
pin-inputdata-variant, data-size, data-complete, data-disabledThe root, a role="group", holding the hidden form input.
pin-input-group—A run of slots.
pin-input-slotdata-complete, data-disabled, aria-invalidOne text box.
pin-input-separator—The dash between groups, hidden from screen readers.

Keyboard

KeyAction
ArrowLeft / ArrowRightMoves focus to the previous or next slot.
BackspaceClears the slot, or moves back and clears the previous one when empty.
DeleteClears the slot.
Home / EndMoves focus to the first or last slot.

Changelog

  1. registry 0.22.0

    939037b — A focused text control that is :user-invalid (a required Input, Textarea, InputFloating or PinInput slot left empty) keeps its destructive border; the focus border used to win over it, leaving a primary outer edge around a destructive inner ring.

  2. registry 0.21.0

    95a0fa1 — Parts follow their root's size through CSS variables instead of the context, so a class on a part wins over the size. PinInput sets --pin-input-slot, TagsInput --tags-input-line and --tags-input-delete, and PinInput, InputNumber, TagsInput and InputGroup set --control-text and --control-text-leading for the field inside (textControlText and textControlInnerText in @/ui/input). NavigationMenu's triggers and links read the --nav-* variables of the menu instead of setting their own, and DataTable's sort buttons and row toggles shrink at xs through the table's variables. PinInput's slots now sit --control-gap-* apart (2px wider at sm, lg and xl); nothing else moves. inputNumberInputVariants, tagsInputInputVariants and tagsInputItemDeleteVariants became the strings inputNumberInput, tagsInputInput and tagsInputItemDelete, inputGroupControlText is gone, and pinInputSlotVariants lost its size key.

  3. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.

  4. registry 0.7.0

    c08ee4f — PinInput: PinInput, PinInputGroup, PinInputSlot and PinInputSeparator over Reka UI's pin input, with the text control variants and sizes of Input, one-time-code autofill on by default, and label, state and error from a surrounding Field.