TagInput
Examples
Size variants
Available ui
prop values for size: xs
/ s
/ m
/ l
.
<template>
<article>
<section>
<veui-tag-input
v-model="valueL"
ui="l"
/>
</section>
<section>
<veui-tag-input v-model="valueM"/>
</section>
<section>
<veui-tag-input
v-model="valueS"
ui="s"
/>
</section>
<section>
<veui-tag-input
v-model="valueXs"
ui="xs"
/>
</section>
</article>
</template>
<script>
import { TagInput } from 'veui'
export default {
components: {
'veui-tag-input': TagInput
},
data () {
return {
valueS: ['Small'],
valueL: ['Large'],
valueM: ['Normal'],
valueXs: ['Extra small']
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 1em;
}
</style>
Read-only
Use the readonly
prop to set the input to readonly state.
<template>
<article>
<section>
<veui-checkbox v-model="readonly">
Read-only
</veui-checkbox>
</section>
<section>
<section>
<veui-tag-input
v-model="valueL"
ui="l"
:readonly="readonly"
/>
</section>
<section>
<veui-tag-input
v-model="valueM"
:readonly="readonly"
/>
</section>
<section>
<veui-tag-input
v-model="valueS"
ui="s"
:readonly="readonly"
/>
</section>
<section>
<veui-tag-input
v-model="valueXs"
ui="xs"
:readonly="readonly"
/>
</section>
</section>
</article>
</template>
<script>
import { TagInput, Checkbox } from 'veui'
export default {
components: {
'veui-tag-input': TagInput,
'veui-checkbox': Checkbox
},
data () {
return {
valueS: ['Small'],
valueL: ['Large'],
valueM: ['Normal'],
valueXs: ['Extra small'],
readonly: true
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 1em;
}
</style>
Disabled
Use the disabled
prop to disable the input.
<template>
<article>
<section>
<veui-checkbox v-model="disabled">
Disabled
</veui-checkbox>
</section>
<section>
<section>
<veui-tag-input
v-model="valueL"
ui="l"
:disabled="disabled"
/>
</section>
<section>
<veui-tag-input
v-model="valueM"
:disabled="disabled"
/>
</section>
<section>
<veui-tag-input
v-model="valueS"
ui="s"
:disabled="disabled"
/>
</section>
<section>
<veui-tag-input
v-model="valueXs"
ui="xs"
:disabled="disabled"
/>
</section>
</section>
</article>
</template>
<script>
import { TagInput, Checkbox } from 'veui'
export default {
components: {
'veui-tag-input': TagInput,
'veui-checkbox': Checkbox
},
data () {
return {
valueS: ['Small'],
valueL: ['Large'],
valueM: ['Normal'],
valueXs: ['Extra small'],
disabled: true
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 1em;
}
</style>
Allow duplicate
Use the allow-duplicate
prop to allow duplicate tags.
<template>
<article>
<section>
<veui-checkbox v-model="allowDuplicate">
Allow duplicate
</veui-checkbox>
</section>
<section>
<veui-tag-input
v-model="value"
:allow-duplicate="allowDuplicate"
/>
</section>
</article>
</template>
<script>
import { TagInput, Checkbox } from 'veui'
export default {
components: {
'veui-tag-input': TagInput,
'veui-checkbox': Checkbox
},
data () {
return {
allowDuplicate: true,
value: ['Steve', 'Steve']
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 1em;
}
</style>
Maximum tags
Use the max
prop to limit the maximum number of tags.
Max tag count
<template>
<article>
<section>
<h4>Max tag count</h4>
<veui-number-input v-model="max"/>
</section>
<section>
<veui-tag-input
v-model="value"
:max="max"
/>
</section>
</article>
</template>
<script>
import { TagInput, NumberInput } from 'veui'
export default {
components: {
'veui-tag-input': TagInput,
'veui-number-input': NumberInput
},
data () {
return {
max: 3,
value: ['Tony', 'Steve']
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 1em;
}
</style>
Maximum characters
Use the maxlength
prop to limit the maximum number of characters.
Max tag length
<template>
<article>
<section>
<h4>Max tag length</h4>
<veui-number-input v-model="maxlength"/>
</section>
<section>
<veui-tag-input
v-model="value"
:maxlength="maxlength"
/>
</section>
</article>
</template>
<script>
import { TagInput, NumberInput } from 'veui'
export default {
components: {
'veui-tag-input': TagInput,
'veui-number-input': NumberInput
},
data () {
return {
maxlength: 6,
value: ['Tony', 'Steve']
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 1em;
}
</style>
Custom tags
Use the tag
slot to customize the display of tags.
<template>
<article>
<section>
<veui-tag-input v-model="value">
<template #tag="{ tag, attrs, listeners }">
<veui-tag
ui="bordered"
color="violet"
v-bind="attrs"
v-on="listeners"
>
{{ tag }}
</veui-tag>
</template>
</veui-tag-input>
</section>
</article>
</template>
<script>
import { TagInput, Tag } from 'veui'
export default {
components: {
'veui-tag-input': TagInput,
'veui-tag': Tag
},
data () {
return {
value: ['Stephen', 'Wanda', 'Carol']
}
}
}
</script>
API
Props
Name | Type | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ui | string | - | Predefined styles.
| ||||||||||
value | string | - |
The value of the input tags list. | ||||||||||
input-value | string | '' |
The value of the text input box. | ||||||||||
disabled | boolean | false | Whether the tag input is disabled. | ||||||||||
readonly | boolean | false | Whether the tag input is read-only. | ||||||||||
placeholder | string | - | Input placeholder. | ||||||||||
clearable | boolean | false | Whether to show the clear button. | ||||||||||
autofocus | boolean | false | Whether to autofocus the tag input. | ||||||||||
maxlength | number | - | The maximum number of characters that can be entered. | ||||||||||
max | number | - | The maximum number of tags that can be added. | ||||||||||
strict | boolean | Object | false | When
| ||||||||||
get-length | function(string): number | - | A custom function to calculate the length of characters. | ||||||||||
allow-duplicate | boolean | false | Whether to allow duplicate tags. |
Slots
Name | Description | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tag | The added tag items. Default content: The tag items rendered by the
|
Events
Name | Description |
---|---|
change |
Triggered when the content of the tag list changes. The callback function takes |
input |
Triggered when the input content in the text box changes. The callback function takes |
clear | Triggered when the clear button is clicked. |
In addition, TagInput
supports the following native events:
auxclick
, click
, contextmenu
, dblclick
, mousedown
, mouseenter
, mouseleave
, mousemove
, mouseover
, mouseout
, mouseup
, select
, wheel
, keydown
, keypress
, keyup
, focus
, blur
, focusin
, and focusout
.
The parameters of the callback function are all native event objects.
Icons
Name | Description |
---|---|
remove | The clear button. |