InputTag Tag Input
LhInputTag tag input: press Enter to add a tag, Backspace to remove the last one, with configurable trigger, max count and duplicate control.
Basic Usage
Basic Usage
VueVite
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhInputTag } from '@lh-ui/vue3'
const tags = ref(['Vue', 'Vite'])
const t1 = {
placeholder: 'Type and press Enter',
}
</script>
<template>
<LhInputTag v-model="tags" :placeholder="t1.placeholder" />
</template>vue
<script>
import { LhInputTag } from '@lh-ui/vue3'
export default {
components: { LhInputTag },
data() {
return {
tags: ['Vue', 'Vite'],
t1: {
placeholder: 'Type and press Enter',
},
}
},
}
</script>
<template>
<LhInputTag v-model="tags" :placeholder="t1.placeholder" />
</template>Trigger & Max
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhInputTag } from '@lh-ui/vue3'
const tags2 = ref([])
const t2 = {
placeholder2: 'Space to add, max 5',
}
</script>
<template>
<LhInputTag v-model="tags2" trigger="space" :max="5" :placeholder="t2.placeholder2" />
</template>vue
<script>
import { LhInputTag } from '@lh-ui/vue3'
export default {
components: { LhInputTag },
data() {
return {
tags2: [],
t2: {
placeholder2: 'Space to add, max 5',
},
}
},
}
</script>
<template>
<LhInputTag v-model="tags2" trigger="space" :max="5" :placeholder="t2.placeholder2" />
</template>InputTag API
Props
| Name | Description | Type | Default |
|---|---|---|---|
| modelValue | Tag list (v-model) | string[] | () => [] |
| trigger | Submit trigger key: enter / space / comma | "enter" | "space" | "comma" | 'enter' |
| placeholder | Placeholder | string | '' |
| max | Max tag count (non-positive = unlimited) | number | 0 |
| allowDuplicate | Allow duplicate tags | boolean | false |
| readonly | Read-only | boolean | false |
| disabled | Disabled | boolean | false |
| ariaLabel | Accessibility name of the input | string | — |
| sx | Quick layout props | LhSxProps | — |
Events
| Name | Description | Type |
|---|---|---|
| update:modelValue | Fired when the tag list changes | (value: string[]) |
| change | Fired when the tag list changes | (value: string[]) |
| add | Fired when a tag is added | (tag: string) |
| remove | Fired when a tag is removed | (tag: string) |
Accessibility
- The input has an
aria-label; each remove button announces the removed tag - Backspace removes the last tag when the input is empty
Type Definitions
The TypeScript type structures exported by this component (auto-extracted from packages/components/input-tag/src/types.ts and @lh-ui/share/core/* sources; click each entry to expand; see the Props table above for attribute descriptions):
LhInputTagProps
ts
export interface LhInputTagProps {
modelValue?: string[]
trigger?: LhInputTagTrigger
placeholder?: string
max?: number
allowDuplicate?: boolean
readonly?: boolean
disabled?: boolean
ariaLabel?: string
sx?: LhSxProps
}
