Pin Input
Features
- Full keyboard navigation.
- Can be controlled or uncontrolled.
- Supports pasting from clipboard
- Emit event when inputs were filled.
Installation
Install the component from your command line.
$ npm add reka-uiAnatomy
Import all parts and piece them together.
<script setup>
import { PinInputInput, PinInputRoot } from 'reka-ui'
</script>
<template>
<PinInputRoot>
<PinInputInput />
</PinInputRoot>
</template>API Reference
Root
Contains all the parts of a pin. An input will also render when used within a form to ensure events propagate correctly.
| Data Attribute | Value |
|---|---|
[data-complete] | Present when completed |
[data-disabled] | Present when disabled |
Input
Input field for Pin Input. You can add as many input as you like.
| Data Attribute | Value |
|---|---|
[data-complete] | Present when completed |
[data-disabled] | Present when disabled |
Examples
OTP mode
You can set the pin input to otp mode by setting otp to true.
<script setup lang="ts">
import { Label, PinInputInput, PinInputRoot } from 'reka-ui'
</script>
<template>
<PinInputRoot v-model="value" otp>
…
</PinInputRoot>
</template>Numeric mode
You can set the pin input to only accept number type by setting type to number.
<script setup lang="ts">
import { Label, PinInputInput, PinInputRoot } from 'reka-ui'
</script>
<template>
<PinInputRoot v-model="value" type="number">
…
</PinInputRoot>
</template>Real-world examples
- Pin Input OTP: A one-time-code field that verifies on complete, handles paste, reports failure, and throttles resends.
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
ArrowLeft | Focus on previous input. |
ArrowRight | Focus on next input. |
Home | Focus on the first input. |
End | Focus on the last input. |
Backspace | Deletes the value of the current input. If the input is empty, moves to the previous input and deletes that value as well. |
Delete | Deletes the value of the current input. |
Ctrl + V |
Pastes the contents of the clipboard into the pin input. If the number of characters in the clipboard equals exceeds the number of inputs, the contents are pasted from the first input. Otherwise, the contents are pasted from the current input onwards. |
In a right-to-left layout (dir="rtl" on PinInputRoot, or on a ConfigProvider), ArrowLeft moves to the next input and ArrowRight to the previous one. See Internationalization.
Headless composable
usePinInput holds the value as an array of characters (modelValue, updateModelValueAt(index, value)), isCompleted and onComplete, registerInput() for each input, and the root part surface with createInputSurface(index) for each cell, which handles typing, paste, Backspace and the arrow keys. It installs a watcher for onComplete, so call it inside setup(). The composable is experimental; see Headless composables.
