<script setup lang="ts">
import { APinInputInput, APinInputRoot } from 'akar';
import { ref } from 'vue';
const value = ref<Array<string>>([]);
function handleComplete(e: Array<string>) {
alert(e.join(''));
}
</script>
<template>
<APinInputRoot
v-model="value"
placeholder="○"
class="inline-flex gap-1.5 items-center relative"
@complete="handleComplete"
>
<APinInputInput
v-for="(id, index) in 5"
:key="id"
:index="index"
class="text-sm color-text-highlighted text-center border-0 rounded-md bg-background size-8 ring ring-ring-accented ring-inset transition-colors-280 placeholder:color-text-dimmed focus:outline-none disabled:opacity-75 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset"
/>
</APinInputRoot>
</template>
Import all parts and piece them together.
<script setup>
import { APinInputInput, APinInputRoot } from 'akar';
</script>
<template>
<APinInputRoot>
<APinInputInput />
</APinInputRoot>
</template>
One benefit of using Akar is its flexibility and low-level control over the components. However, this also means that you may need to manually construct more complex UI elements by combining multiple Akar components together.
If you feel there's a lot of elements that needs to be constructed manually using Akar, consider using Pohon UI instead. It provides a higher-level abstraction over Akar components with pre-defined styles and behaviors that can help you build UIs faster.
Contains all the parts of a pin. An input will also render when used within a form to ensure events propagate correctly.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
defaultValue | string[]The default value of the pin inputs when it is initially rendered. Use when you do not need to control its checked state. | |
dir | 'ltr' | 'rtl'The reading direction of the combobox when applicable. | |
disabled | booleanWhen | |
id | stringId of the element | |
mask | booleanWhen | |
modelValue | string[] | null | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
otp | booleanWhen | |
placeholder | '' | stringThe placeholder character to use for empty pin-inputs. |
required | booleanWhen | |
type | 'text' as any | 'number' | 'text'Input type for the inputs. |
| Event | Type |
|---|---|
complete | [value: string[]] |
update:modelValue | [value: string[]]Event handler called when the value changes. |
| Slot | Type |
|---|---|
modelValue | string[]The controlled checked state of the pin input. Can be binded as |
| Attribute | Value |
|---|---|
[data-complete] | Present when all inputs are filled |
[data-disabled] | Present when disabled |
Input field for Pin Input. You can add as many input as you like.
| Prop | Default | Type |
|---|---|---|
as | 'input' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
disabled | booleanWhen | |
index* | numberPosition of the value this input binds to. |
| Attribute | Value |
|---|---|
[data-complete] | Present when all inputs are filled |
[data-disabled] | Present when disabled |
You can set the pin input to otp mode by setting otp to true.
<script setup lang="ts">
import { Label, APinInputInput, APinInputRoot } from 'akar'
</script>
<template>
<APinInputRoot v-model="value" otp>
…
</APinInputRoot>
</template>
``
### Numeric mode
You can set the pin input to only accept `number` type by setting type to `number`.
```vue{6}
<script setup lang="ts">
import { Label, APinInputInput, APinInputRoot } from 'akar'
</script>
<template>
<APinInputRoot v-model="value" type="number">
…
</APinInputRoot>
</template>
| 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. |