Tags Input
Enter and manage a list of tags.
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 TagsInput.vue and index.ts into app/components/ui/tags-input/.
app/components/ui/tags-input/TagsInput.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 |
Size scales the tags and the field together. The text-side inset balances the visible space around the remove icon; increasing size grows the tag rather than adding empty space around it.
| Size | Field minimum | Tag height | Text | Remove icon |
|---|---|---|---|---|
| xs | 24px | 20px | 12px | 12px |
| sm | 28px | 22px | 13px | 14px |
| md | 32px | 24px | 14px | 16px |
| lg | 36px | 28px | 14px | 18px |
| xl | 40px | 32px | 16px | 20px |
The field grows when tags wrap. Touch removal targets remain at least 44px while their icons keep the selected size.
Models
| Model | Type | Default | Description |
|---|---|---|---|
v-model | TagsInputValue[] | [] | Accepted tag values. |
v-model:input | string | "" | Current uncommitted text. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
displayValue | (value) => string | string/JSON | Visible and accessible tag label. |
convertValue | (text) => value | identity string | Converts input text before validation/addition. |
serializeValue | (value) => string | string/JSON | Serializes native form values and keys. |
isEqual | (a, b) => boolean | Object.is | Duplicate and equality comparison. |
validate | (value) => boolean | accepts all | Validates converted values. |
delimiter | string | RegExp | "," | Add key and paste splitting rule. |
addOnBlur | boolean | false | Adds non-empty input on blur. |
addOnPaste | boolean | false | Adds multiple delimited clipboard values. |
addOnTab | boolean | false | Adds non-empty input instead of moving focus. |
duplicate | boolean | false | Allows equal values more than once. |
max | number | 0 | Maximum count; zero means unlimited. |
trim | boolean | true | Trims input and pasted segments. |
clearable | boolean | false | Renders a clear-all button when values exist. |
placeholder | string | - | Editable input placeholder. |
maxLength | number | - | Native character limit for uncommitted input text. |
autoFocus | boolean | false | Focuses the editable input after mount. |
id | string | field/generated id | Editable input id. |
name | string | field name | Native form field name repeated per tag. |
required | boolean | false | Requires at least one tag. |
disabled | boolean | false | Disables editing, controls, and form submission. |
readOnly | boolean | false | Keeps values focusable but prevents changes. |
invalid | boolean | false | Forces invalid styling and ARIA state. |
dir | "ltr" | "rtl" | "ltr" | Tag direction and Arrow-key behavior. |
ariaLabel | string | "Tags input" | Accessible group/input label. |
ariaLabelledby | string | - | Accessible label element id. |
ariaDescribedby | string | field IDs | Accessible description/error ids. |
ui | TagsInputUi | - | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
tag | value, label, index, isHighlighted, remove | Complete custom tag. |
delete | value, index | Default remove button content. |
input | value, inputProps, add | Custom editable input. Bind inputProps. |
clear | - | Clear-all button content. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | (values, details) | Fires before the values array updates. Cancelable. |
input-change | (text, details) | Fires before editable text updates. Cancelable. |
add | (value, details) | Fires before an accepted value is added. Cancelable. |
remove | (value, details) | Fires before a value is removed. Cancelable. |
invalid-value | (value, details) | Reports empty, convert, invalid, duplicate, or max reasons. |
Keyboard
| Key | Behavior |
|---|---|
Enter / delimiter key | Add current text. |
Tab | Add when addOnTab; otherwise move focus normally. |
input Backspace | Focus last tag when input is empty. |
| input boundary Arrow | Focus last tag from the start edge, respecting dir. |
tag ArrowLeft / ArrowRight | Move between tags/input, respecting dir. |
tag Home / End | Focus first/last tag. |
tag Backspace / Delete | Remove focused tag and retain logical focus. |
tag Escape | Return focus to the editable input. |