Search docs

Pin Input

Multi-digit verification code and PIN input group.

Pin Input renders a role="group" of native <input> elements with automatic focus advance, Backspace navigation, paste distribution, and an optional HiddenInput for form submission.

import { component$, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <PinInput.Root length={4} aria-label="Verification code" class="pin-input-default">
      <PinInput.Input index={0} class="pin-input-default-input" />
      <PinInput.Input index={1} class="pin-input-default-input" />
      <PinInput.Input index={2} class="pin-input-default-input" />
      <PinInput.Input index={3} class="pin-input-default-input" />
    </PinInput.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/pin-input

Anatomy#

import { PinInput } from '@leve-ui/pin-input'; // or '@leve-ui/core'

<PinInput.Root length={4}>
  <PinInput.Input index={0} />
  <PinInput.Input index={1} />
  <PinInput.Input index={2} />
  <PinInput.Input index={3} />
  <PinInput.HiddenInput name="code" />
</PinInput.Root>
PartElementDescription
PinInput.Root<div>Group container (role="group") that manages the value array, completion state, and Field wiring.
PinInput.Input<input>Individual character input at a zero-based index.
PinInput.HiddenInput<input>Visually hidden input that submits the joined value in a <form> and resets on form reset.

Examples#

Controlled#

Control the value array with bind:value and handle completion with onComplete$.

Value: empty

Alphanumeric#

Set type="alphanumeric" to accept letters as well as digits.

Mask#

Set mask to render type="password" on each input.

Disabled#

disabled on the Root disables every input in the group.

Read Only#

readOnly prevents editing while keeping the inputs focusable.

With Field#

Inside a Field.Root, Field.Label points to the first input, and Field.Description, Field.ErrorMessage, and inherited states are wired automatically.

Enter the 4-digit code sent to your email.

With Form#

Use PinInput.HiddenInput to submit the joined PIN in a <form> and reset all inputs on form reset.

API Reference#

Root#

PropDefaultType
ids–{ root?: string; input?: string }

Overrides the element IDs of the parts. Inside a Field, the first input ID comes from the Field.

length–number

Total number of digit inputs, used for accessible labels (e.g. "Digit 1 of 6") and completion detection.

defaultValue[]string[]

The initial PIN value array (uncontrolled).

bind:value–Signal<string[]>

A signal with the PIN value array (controlled).

onValueChange$–QRL<(value: string[]) => void>

Called when the PIN value array changes.

onComplete$–QRL<(value: string) => void>

Called with the joined PIN string when all slots become filled.

type'numeric''numeric' | 'alphanumeric'

The type of characters allowed in the PIN inputs.

maskfalseboolean

Whether to mask the input characters (renders type="password").

otptrueboolean

Whether to set autocomplete="one-time-code" on the first input.

placeholder'○'string

The placeholder character shown in empty inputs.

disabledfalseboolean

Disables all PIN inputs. Inside a Field or Fieldset, the inherited disabled also applies.

readOnlyfalseboolean

Marks all PIN inputs as read-only. Inside a Field, the Field's readOnly also applies.

requiredfalseboolean

Marks the PIN input as required. Inside a Field, the Field's required also applies.

invalidfalseboolean

Marks the PIN input as invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <div> attributes.

Data attributeValue
data-leve-pin-inputAlways present
data-state"complete" | "incomplete"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Input#

PropDefaultType
index (required)–number

Zero-based index of this digit input within the group.

disabledfalseboolean

Disables this individual input.

readOnlyfalseboolean

Marks this individual input as read-only.

invalidfalseboolean

Marks this individual input as invalid.

Also accepts all <input> attributes.

Data attributeValue
data-leve-pin-input-inputAlways present
data-state"filled" | "empty"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

HiddenInput#

PropDefaultType
form–string

The id of the form element to associate the input with.

Also accepts all <input> attributes.

Data attributeValue
data-leve-pin-input-hidden-inputAlways present
data-state"complete" | "incomplete"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Accessibility#

Uses a role="group" container of native <input> elements.

  • Provide an accessible name for PinInput.Root via Field.Label, aria-label, or aria-labelledby.
  • Each PinInput.Input outputs a default aria-label such as "Digit 1 of 4" (when length is set) or "Digit 1".
  • Inside Field.Root, Field.Label's for attribute is wired to the first PinInput.Input (index={0}).
  • PinInput.HiddenInput is hidden from assistive technology and tab order with aria-hidden="true" and tabIndex={-1}.

Keyboard Interactions#

KeyDescription
CharacterFills the current slot with a valid character and moves focus to the next input.
BackspaceClears the current slot if filled; otherwise moves focus to the previous input and clears it.
DeleteClears the current slot.
ArrowLeft / ArrowRightMoves focus to the previous or next input (respecting RTL direction).
Home / EndMoves focus to the first or last enabled input.
PasteFilters pasted text to valid characters and fills slots starting from index 0 (if full length) or the current index.