Pin / OTP Input
Enter a verification code or PIN across separate cells.
Demos
Size
Variant
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy PinInput.vue and index.ts into app/components/ui/pin-input/.
app/components/ui/pin-input/PinInput.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | outline, soft, bare | outline |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
length | number | 4 | Number of cells; clamped to at least one. |
type | "text" | "number" | "text" | Character mode and input metadata. |
mask | boolean | false | Renders password cells. |
otp | boolean | false | Enables one-time-code autocomplete on the first cell. |
placeholder | string | "" | Placeholder applied to every cell. |
allowedChars | RegExp | (character) => boolean | non-whitespace | Additional character filter. |
selectOnFocus | boolean | true | Selects a cell value when focused. |
autoFocus | boolean | false | Focuses the first cell after mount. |
id | string | field/generated id | First cell id. Later cells receive numbered suffixes. |
name | string | field name | Native form field name. |
required | boolean | false | Requires all cells to be filled. |
disabled | boolean | false | Disables every cell and form submission. |
readOnly | boolean | false | Prevents value changes while retaining focus. |
invalid | boolean | false | Forces invalid styling and ARIA state. |
dir | "ltr" | "rtl" | "ltr" | Cell direction and Arrow-key behavior. |
ariaLabel | string | "Pin input" | Group label and per-cell label prefix. |
ariaLabelledby | string | - | Accessible label element id. |
ariaDescribedby | string | field IDs | Accessible description/error ids. |
ui | PinInputUi | - | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
cell | index, value, isFilled, isActive, inputProps | Custom cell. Bind inputProps to an input. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | (value, details) | Fires before the canonical value updates. Cancelable. |
complete | (value, details) | Fires after every cell becomes filled. |
Keyboard
| Key | Behavior |
|---|---|
| text input | Accepts valid characters and advances focus. Multiple characters distribute forward. |
| paste | Distributes valid characters from the current cell. |
ArrowLeft / ArrowRight | Move between cells, respecting dir. |
Home / End | Focus first/last cell. |
Backspace | Clears current cell, or previous cell when current is empty. |
Delete | Clears current cell. |