一键导入
n-dynamic-tags
A component for dynamically adding and removing tags with customizable input and trigger elements
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
A component for dynamically adding and removing tags with customizable input and trigger elements
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Naive UI Skills Library - A comprehensive skill library for AI agents to understand and utilize Naive UI components. Invoke when user needs to work with Naive UI components, theming, i18n, dark mode, or design specifications.
Affix component that makes content stick to fixed places when scrolling. Invoke when user needs to implement sticky positioning or fixed elements in Naive UI.
Alert component for displaying important messages and notifications. Invoke when user needs to show contextual feedback messages with different types and styles in Naive UI.
Anchor component for navigation and table of contents. Invoke when user needs to implement anchor navigation, table of contents, or scroll-based navigation highlighting in Naive UI.
An autocomplete input component that provides search hints and suggestions as users type, with support for grouping, custom rendering, and various input configurations
Avatar component for displaying user profile images, icons, or text. Invoke when user needs to implement user avatars, avatar groups, or customize avatar appearance in Naive UI.
| name | n-dynamic-tags |
| description | A component for dynamically adding and removing tags with customizable input and trigger elements |
| author | jiaiyan |
| version | 1.0.0 |
The n-dynamic-tags component allows users to create and manage tags dynamically. Tags can be added by typing and pressing Enter, and removed by clicking the close button. It supports custom rendering and input elements.
Use n-dynamic-tags when you need to:
<template>
<n-dynamic-tags v-model:value="tags" />
</template>
<script setup>
import { ref } from 'vue'
const tags = ref(['Tag 1', 'Tag 2'])
</script>
<template>
<n-dynamic-tags v-model:value="tags" :max="3" />
</template>
<template>
<n-space vertical>
<n-dynamic-tags v-model:value="tags" type="primary" />
<n-dynamic-tags v-model:value="tags" type="info" />
<n-dynamic-tags v-model:value="tags" type="success" />
<n-dynamic-tags v-model:value="tags" type="warning" />
<n-dynamic-tags v-model:value="tags" type="error" />
<n-dynamic-tags v-model:value="tags" round />
</n-space>
</template>
| Name | Type | Default | Description |
|---|---|---|---|
value / v-model:value | string[] | DynamicTagsOption[] | undefined | Value if manually set. |
default-value | string[] | [] | Default value. |
disabled | boolean | false | Whether the tag is disabled. |
closable | boolean | true | Whether the tag is closable. |
max | number | undefined | Maximum number of tags. |
size | 'small' | 'medium' | 'large' | 'medium' | Size of the tag. |
type | 'default' | 'primary' | 'info' | 'success' | 'warning' | 'error' | 'default' | Type of the tag. |
round | boolean | false | Whether the tag has rounded corners. |
color | { color?: string, borderColor?: string, textColor?: string } | undefined | Color of the tag. Overrides color set by type. |
render-tag | (tag: string | DynamicTagsOption, index: number) => VNodeChild | undefined | Custom render tag function. |
input-props | InputProps | undefined | Props of internal n-input. |
input-style | string | Object | undefined | Customize the style of the input. |
input-class | string | undefined | Customize the class of the input. |
tag-style | string | Object | undefined | Customize the style of the tag. |
tag-class | string | undefined | Customize the class of the tag. |
interface DynamicTagsOption {
label: string
value: string
}
| Name | Parameters | Description |
|---|---|---|
update:value | (value: string[] | DynamicTagsOption[]) => void | Callback when value changes. |
create | (label: string) => string | DynamicTagsOption | Create derived value from input. |
| Name | Parameters | Description |
|---|---|---|
input | { submit: (value: any) => void, deactivate: () => void } | Custom element to replace the regular input. |
trigger | { activate: () => void, disabled: boolean } | Element that triggers the tag to switch to input. |
<template>
<n-dynamic-tags v-model:value="tags">
<template #input="{ submit, deactivate }">
<n-auto-complete
ref="autoCompleteInstRef"
v-model:value="inputValue"
size="small"
:options="options"
placeholder="Email"
:clear-after-select="true"
@select="submit($event)"
@blur="deactivate"
/>
</template>
</n-dynamic-tags>
</template>
<script setup>
import { ref } from 'vue'
const tags = ref([])
const inputValue = ref('')
const options = ref([
{ label: 'user1@example.com', value: 'user1@example.com' },
{ label: 'user2@example.com', value: 'user2@example.com' }
])
</script>
<template>
<n-dynamic-tags v-model:value="tags" :render-tag="renderTag" />
</template>
<script setup>
import { h } from 'vue'
import { NTag } from 'naive-ui'
const tags = ref(['Apple', 'Banana', 'Orange'])
const renderTag = (tag, index) => {
return h(
NTag,
{
type: 'primary',
bordered: false,
closable: true,
onClose: () => tags.value.splice(index, 1)
},
{ default: () => tag }
)
}
</script>
<template>
<n-dynamic-tags v-model:value="value" @create="onCreate" />
<pre>{{ JSON.stringify(value, null, 2) }}</pre>
</template>
<script setup>
import { ref } from 'vue'
const value = ref([
{ label: 'Vue', value: 'vue' },
{ label: 'React', value: 'react' }
])
const onCreate = (label) => {
return {
label,
value: label.toLowerCase().replace(/\s+/g, '-')
}
}
</script>
<template>
<n-dynamic-tags @create="handleCreate" />
</template>
<script setup>
const handleCreate = (label) => {
if (label.length < 2) {
return label
}
return label.toUpperCase()
}
</script>
<template>
<n-form :model="model" :rules="rules">
<n-form-item path="tags" :show-label="false">
<n-dynamic-tags v-model:value="model.tags" />
</n-form-item>
</n-form>
</template>
<script setup>
import { ref } from 'vue'
const model = ref({
tags: []
})
const rules = {
tags: {
type: 'array',
required: true,
message: 'At least one tag is required'
}
}
</script>
Use max to limit tag count: Set a maximum number of tags to prevent excessive input.
Customize input with slots: Use the input slot for autocomplete or other input components.
Use on-create for value transformation: Transform user input before adding as a tag (e.g., lowercase, trim).
Use object format for complex data: When tags need both display label and value, use DynamicTagsOption format.
Combine with form validation: Wrap in n-form-item for validation support.