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>
);
});.pin-input-default {
display: inline-flex;
gap: 8px;
font-family: inherit;
}
.pin-input-default-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-default-input::placeholder {
color: light-dark(#475569, #c9ddf0);
}
.pin-input-default-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.pin-input-default[data-state="complete"] .pin-input-default-input {
border-color: #009dfd;
}Installation#
Install the individual package, or use @leve-ui/core to get every component at once:
pnpm add @leve-ui/pin-inputnpm install @leve-ui/pin-inputyarn add @leve-ui/pin-inputbun add @leve-ui/pin-inputpnpm add @leve-ui/corenpm install @leve-ui/coreyarn add @leve-ui/corebun add @leve-ui/coreAnatomy#
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>
| Part | Element | Description |
|---|---|---|
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$.
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './controlled.css?inline';
export default component$(() => {
useStyles$(styles);
const value = useSignal<string[]>(['', '', '', '']);
const completed = useSignal('');
return (
<div class="pin-input-controlled-wrapper">
<PinInput.Root
length={4}
bind:value={value}
onComplete$={(pin) => {
completed.value = pin;
}}
aria-label="One-time code"
class="pin-input-controlled"
>
<PinInput.Input index={0} class="pin-input-controlled-input" />
<PinInput.Input index={1} class="pin-input-controlled-input" />
<PinInput.Input index={2} class="pin-input-controlled-input" />
<PinInput.Input index={3} class="pin-input-controlled-input" />
</PinInput.Root>
<div class="pin-input-controlled-meta">
<span>Value: {value.value.join('') || 'empty'}</span>
{completed.value && <span>Completed: {completed.value}</span>}
<button
type="button"
class="pin-input-controlled-clear"
onClick$={() => {
value.value = ['', '', '', ''];
completed.value = '';
}}
>
Clear
</button>
</div>
</div>
);
});.pin-input-controlled-wrapper {
display: inline-flex;
flex-direction: column;
gap: 12px;
font-family: inherit;
}
.pin-input-controlled {
display: inline-flex;
gap: 8px;
}
.pin-input-controlled-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-controlled-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.pin-input-controlled-meta {
display: flex;
align-items: center;
gap: 12px;
color: light-dark(#475569, #c9ddf0);
font-size: 13px;
}
.pin-input-controlled-clear {
padding: 4px 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pin-input-controlled-clear:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.pin-input-controlled-clear:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}Alphanumeric#
Set type="alphanumeric" to accept letters as well as digits.
import { component$, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './alphanumeric.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<PinInput.Root
length={4}
type="alphanumeric"
aria-label="Alphanumeric code"
class="pin-input-alphanumeric"
>
<PinInput.Input index={0} class="pin-input-alphanumeric-input" />
<PinInput.Input index={1} class="pin-input-alphanumeric-input" />
<PinInput.Input index={2} class="pin-input-alphanumeric-input" />
<PinInput.Input index={3} class="pin-input-alphanumeric-input" />
</PinInput.Root>
);
});.pin-input-alphanumeric {
display: inline-flex;
gap: 8px;
font-family: inherit;
}
.pin-input-alphanumeric-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-alphanumeric-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}Mask#
Set mask to render type="password" on each input.
import { component$, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './mask.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<PinInput.Root
length={4}
mask
defaultValue={['1', '2', '', '']}
aria-label="Masked PIN"
class="pin-input-mask"
>
<PinInput.Input index={0} class="pin-input-mask-input" />
<PinInput.Input index={1} class="pin-input-mask-input" />
<PinInput.Input index={2} class="pin-input-mask-input" />
<PinInput.Input index={3} class="pin-input-mask-input" />
</PinInput.Root>
);
});.pin-input-mask {
display: inline-flex;
gap: 8px;
font-family: inherit;
}
.pin-input-mask-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-mask-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}Disabled#
disabled on the Root disables every input in the group.
import { component$, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './disabled.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<PinInput.Root
length={4}
disabled
defaultValue={['1', '2', '', '']}
aria-label="Disabled PIN"
class="pin-input-disabled"
>
<PinInput.Input index={0} class="pin-input-disabled-input" />
<PinInput.Input index={1} class="pin-input-disabled-input" />
<PinInput.Input index={2} class="pin-input-disabled-input" />
<PinInput.Input index={3} class="pin-input-disabled-input" />
</PinInput.Root>
);
});.pin-input-disabled {
display: inline-flex;
gap: 8px;
font-family: inherit;
}
.pin-input-disabled-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-disabled-input[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}Read Only#
readOnly prevents editing while keeping the inputs focusable.
import { component$, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './read-only.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<PinInput.Root
length={4}
readOnly
defaultValue={['4', '8', '1', '5']}
aria-label="Read-only PIN"
class="pin-input-read-only"
>
<PinInput.Input index={0} class="pin-input-read-only-input" />
<PinInput.Input index={1} class="pin-input-read-only-input" />
<PinInput.Input index={2} class="pin-input-read-only-input" />
<PinInput.Input index={3} class="pin-input-read-only-input" />
</PinInput.Root>
);
});.pin-input-read-only {
display: inline-flex;
gap: 8px;
font-family: inherit;
}
.pin-input-read-only-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#f1f5f9, #ffffff14);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-read-only-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}With Field#
Inside a Field.Root, Field.Label points to the first input, and Field.Description, Field.ErrorMessage, and inherited states are wired automatically.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Field } from '@leve-ui/field';
import { PinInput } from '@leve-ui/pin-input';
import styles from './with-field.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Field.Root hasDescription required class="pin-input-with-field-field">
<Field.Label class="pin-input-with-field-label">Security code</Field.Label>
<PinInput.Root length={4} class="pin-input-with-field">
<PinInput.Input index={0} class="pin-input-with-field-input" />
<PinInput.Input index={1} class="pin-input-with-field-input" />
<PinInput.Input index={2} class="pin-input-with-field-input" />
<PinInput.Input index={3} class="pin-input-with-field-input" />
</PinInput.Root>
<Field.Description class="pin-input-with-field-description">
Enter the 4-digit code sent to your email.
</Field.Description>
</Field.Root>
);
});.pin-input-with-field-field {
display: inline-flex;
flex-direction: column;
gap: 8px;
font-family: inherit;
}
.pin-input-with-field-label {
color: light-dark(#0f172a, #ffffff);
font-size: 14px;
font-weight: 500;
}
.pin-input-with-field {
display: inline-flex;
gap: 8px;
}
.pin-input-with-field-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-with-field-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.pin-input-with-field-input[data-invalid] {
border-color: light-dark(#dc2626, #f87171);
}
.pin-input-with-field-description {
margin: 0;
color: light-dark(#475569, #c9ddf0);
font-size: 13px;
}With Form#
Use PinInput.HiddenInput to submit the joined PIN in a <form> and reset all inputs on form reset.
import { $, component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { PinInput } from '@leve-ui/pin-input';
import styles from './with-form.css?inline';
export default component$(() => {
useStyles$(styles);
const submittedData = useSignal('');
const handleSubmit$ = $((_event: unknown, form: HTMLFormElement) => {
const formData = new FormData(form);
submittedData.value = JSON.stringify(Object.fromEntries(formData));
});
return (
<div class="pin-input-with-form-wrapper">
<form class="pin-input-with-form-form" preventdefault:submit onSubmit$={handleSubmit$}>
<PinInput.Root
length={4}
defaultValue={['1', '2', '', '']}
required
aria-label="Verification code"
class="pin-input-with-form"
>
<PinInput.Input index={0} class="pin-input-with-form-input" />
<PinInput.Input index={1} class="pin-input-with-form-input" />
<PinInput.Input index={2} class="pin-input-with-form-input" />
<PinInput.Input index={3} class="pin-input-with-form-input" />
<PinInput.HiddenInput name="code" />
</PinInput.Root>
<div class="pin-input-with-form-actions">
<button type="submit" class="pin-input-with-form-submit">
Submit
</button>
<button type="reset" class="pin-input-with-form-reset">
Reset
</button>
</div>
</form>
<output class="pin-input-with-form-output">{submittedData.value}</output>
</div>
);
});.pin-input-with-form-wrapper {
display: inline-flex;
flex-direction: column;
gap: 12px;
font-family: inherit;
}
.pin-input-with-form-form {
display: flex;
flex-direction: column;
gap: 12px;
}
.pin-input-with-form {
position: relative;
display: inline-flex;
gap: 8px;
}
.pin-input-with-form-input {
width: 44px;
height: 48px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 18px;
font-weight: 600;
text-align: center;
}
.pin-input-with-form-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.pin-input-with-form-actions {
display: flex;
gap: 8px;
}
.pin-input-with-form-submit {
padding: 6px 14px;
border: none;
border-radius: 6px;
background: #009dfd;
color: #ffffff;
font-family: inherit;
font-size: 14px;
cursor: pointer;
}
.pin-input-with-form-submit:hover {
background: #006ce9;
}
.pin-input-with-form-reset {
padding: 6px 14px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
cursor: pointer;
}
.pin-input-with-form-reset:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.pin-input-with-form-submit:focus-visible,
.pin-input-with-form-reset:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.pin-input-with-form-output {
color: light-dark(#475569, #c9ddf0);
font-size: 13px;
}API Reference#
Root#
| Prop | Default | Type |
|---|---|---|
| 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. |
| mask | false | boolean Whether to mask the input characters (renders |
| otp | true | boolean Whether to set |
| placeholder | '○' | string The placeholder character shown in empty inputs. |
| disabled | false | boolean Disables all PIN inputs. Inside a Field or Fieldset, the inherited |
| readOnly | false | boolean Marks all PIN inputs as read-only. Inside a Field, the Field's |
| required | false | boolean Marks the PIN input as required. Inside a Field, the Field's |
| invalid | false | boolean Marks the PIN input as invalid. Inside a Field, the Field's |
Also accepts all <div> attributes.
| Data attribute | Value |
|---|---|
data-leve-pin-input | Always present |
data-state | "complete" | "incomplete" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
Input#
| Prop | Default | Type |
|---|---|---|
| index (required) | – | number Zero-based index of this digit input within the group. |
| disabled | false | boolean Disables this individual input. |
| readOnly | false | boolean Marks this individual input as read-only. |
| invalid | false | boolean Marks this individual input as invalid. |
Also accepts all <input> attributes.
| Data attribute | Value |
|---|---|
data-leve-pin-input-input | Always present |
data-state | "filled" | "empty" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
HiddenInput#
| Prop | Default | Type |
|---|---|---|
| form | – | string The |
Also accepts all <input> attributes.
| Data attribute | Value |
|---|---|
data-leve-pin-input-hidden-input | Always present |
data-state | "complete" | "incomplete" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
Accessibility#
Uses a role="group" container of native <input> elements.
- Provide an accessible name for
PinInput.RootviaField.Label,aria-label, oraria-labelledby. - Each
PinInput.Inputoutputs a defaultaria-labelsuch as"Digit 1 of 4"(whenlengthis set) or"Digit 1". - Inside
Field.Root,Field.Label'sforattribute is wired to the firstPinInput.Input(index={0}). PinInput.HiddenInputis hidden from assistive technology and tab order witharia-hidden="true"andtabIndex={-1}.
Keyboard Interactions#
| Key | Description |
|---|---|
| Character | Fills the current slot with a valid character and moves focus to the next input. |
Backspace | Clears the current slot if filled; otherwise moves focus to the previous input and clears it. |
Delete | Clears the current slot. |
ArrowLeft / ArrowRight | Moves focus to the previous or next input (respecting RTL direction). |
Home / End | Moves focus to the first or last enabled input. |
| Paste | Filters pasted text to valid characters and fills slots starting from index 0 (if full length) or the current index. |