PinInput
Data inputA code typed into separate boxes, as one input underneath: <PinInput.Root> (maxlength, bind:value, pattern, onComplete) draws its boxes in one row. To group them, its children snippet gets the cells, each drawn as a PinInput.Cell; PinInput.Group joins cells into one row and PinInput.Separator puts a dash between groups. Typing moves on, Backspace moves back, pasting fills all boxes, and password managers and one-time-code autofill work. Inside a Field the input is labelled, described and marked invalid by the Field.
import { PinInput } from '@limerdev/zest'; Input.Examples
Basic
Six boxes. Pasting a code fills them all.
Sent to your phone. 0/6
<script lang="ts">
import { Field, PinInput } from '@limerdev/zest';
let code = $state('');
</script>
<Field.Root class="w-auto">
<Field.Label>Verification code</Field.Label>
<PinInput.Root maxlength={6} bind:value={code} />
<Field.Description>Sent to your phone. {code.length}/6</Field.Description>
</Field.Root> Groups
The children snippet gets the cells, to split them into groups with a separator.
<script lang="ts">
import { Field, PinInput } from '@limerdev/zest';
let code = $state('');
</script>
<Field.Root class="w-auto">
<Field.Label>Recovery code</Field.Label>
<PinInput.Root maxlength={6} bind:value={code}>
{#snippet children({ cells })}
<PinInput.Group>
{#each cells.slice(0, 3) as cell, index (index)}
<PinInput.Cell {cell} />
{/each}
</PinInput.Group>
<PinInput.Separator />
<PinInput.Group>
{#each cells.slice(3) as cell, index (index)}
<PinInput.Cell {cell} />
{/each}
</PinInput.Group>
{/snippet}
</PinInput.Root>
</Field.Root> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
PinInput.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | – | Whether the input is disabled |
| inputId | string | – | Optionally provide an ID to apply to the hidden input element. |
| inputRef | HTMLInputElement | null | – | The underlying hidden <input> element. Bind to call focus(), read selection, etc. |
| maxlength required | number | – | The max length of the input. |
| onComplete | ((...args: any[]) => void) | – | A callback function that is called when the input is completely filled. |
| onValueChange | OnChangeFn<string> | – | A callback function that is called when the value of the input changes. |
| pasteTransformer | ((text: string) => string) | – | A callback function that is called when the user pastes text into the input. It receives the pasted text as an argument, and should return the sanitized text. Use this function to clean up the pasted text, like removing hyphens or other characters that should not make it into the input. |
| pushPasswordManagerStrategy | "none" | "increase-width" | – | How to handle the input when a password manager is detected. |
| textalign | "right" | "left" | "center" | "left" | Customize the alignment of the text within in the input. |
| value bindable | string | '' | The value of the input. |
PinInput.Cell
| Prop | Type | Default | Description |
|---|---|---|---|
| cell required | PinInputCell | – | This specific cell, which is provided by the cells snippet prop from the PinInput.Root component. |
PinInput.Group
No props of its own beyond the common ones.
PinInput.Separator
No props of its own beyond the common ones.