Pin Input

PohonGitHub
A sequence of one-character alphanumeric inputs.
<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>

Features

  • Full keyboard navigation.
  • Can be controlled or uncontrolled.
  • Supports pasting from clipboard
  • Emit event when inputs were filled.

Anatomy

Import all parts and piece them together.

<script setup>
import { APinInputInput, APinInputRoot } from 'akar';
</script>

<template>
  <APinInputRoot>
    <APinInputInput />
  </APinInputRoot>
</template>

Pohon

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.

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.

Props

Prop Default Type
as'div'APrimitiveAsTag | Component

The element or component this component should render as. Can be overwritten by asChild.

asChildboolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

defaultValuestring[]

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.
If omitted, inherits globally from AConfigProvider or assumes LTR (left-to-right) reading mode.

disabledboolean

When true, prevents the user from interacting with the pin input

idstring

Id of the element

maskboolean

When true, pin inputs will be treated as password.

modelValuestring[] | null
namestring

The name of the field. Submitted with its owning form as part of a name/value pair.

otpboolean

When true, mobile devices will autodetect the OTP from messages or clipboard, and enable the autocomplete field.

placeholder''string

The placeholder character to use for empty pin-inputs.

requiredboolean

When true, indicates that the user must set the value before the owning form can be submitted.

type'text' as any'number' | 'text'

Input type for the inputs.

Emits

Event Type
complete[value: string[]]
update:modelValue[value: string[]]

Event handler called when the value changes.

Slots

Slot Type
modelValuestring[]

The controlled checked state of the pin input. Can be binded as v-model.

Data Attributes

Attribute Value
[data-complete]Present when all inputs are filled
[data-disabled]Present when disabled

Input

Input field for Pin Input. You can add as many input as you like.

Props

Prop Default Type
as'input'APrimitiveAsTag | Component

The element or component this component should render as. Can be overwritten by asChild.

asChildboolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

disabledboolean

When true, prevents the user from interacting with the pin input

index*number

Position of the value this input binds to.

Data Attributes

Attribute Value
[data-complete]Present when all inputs are filled
[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, 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>

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.