Tags Input
Tag inputs render tags inside an input, followed by an actual text input.
Preview
Installation
npx sigma-ui@latest add tags-inputUsage
<script setup lang="ts">
import { ref } from 'vue';
import {
TagsInput,
TagsInputInput,
TagsInputItem,
TagsInputItemDelete,
TagsInputItemText,
} from '@/components/ui/tags-input';
const modelValue = ref(['Apple', 'Banana']);
</script>
<template>
<TagsInput v-model="modelValue">
<TagsInputItem
v-for="item in modelValue"
:key="item"
:value="item"
>
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput placeholder="Fruits..." />
</TagsInput>
</template>v-modelis astring[]. Typing inTagsInputInputand pressing Enter adds a tag.- Render one
TagsInputItemper value, withTagsInputItemTextfor the label andTagsInputItemDeletefor the remove button.
Examples
Tags with Combobox
Combines the tags input with a Combobox so the user picks tags from a filtered list.
API Reference
TagsInput
Props
| Prop | Type | Default |
|---|---|---|
modelValueThe controlled value of the tags input. Can be bind as | AcceptableInputValue[] | null | - |
defaultValueThe value of the tags that should be added. Use when you do not need to control the state of the tags input | AcceptableInputValue[] | - |
addOnPasteWhen | boolean | - |
addOnTabWhen | boolean | - |
addOnBlurWhen | boolean | - |
duplicateWhen | boolean | - |
disabledWhen | boolean | - |
delimiterThe character or regular expression to trigger the addition of a new tag. Also used to split tags for | string | RegExp | - |
dirThe reading direction of the combobox when applicable. <br> If omitted, inherits globally from | Direction | - |
maxMaximum number of tags. | number | - |
id | string | - |
convertValueConvert the input value to the desired type. Mandatory when using objects as values and using | ((value: string) => AcceptableInputValue) | - |
displayValueDisplay the value of the tag. Useful when you want to apply modifications to the value like adding a suffix or when using object as values | ((value: AcceptableInputValue) => string) | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value changes | [payload: AcceptableInputValue[]] |
invalidEvent handler called when the value is invalid | [payload: AcceptableInputValue] |
addTagEvent handler called when tag is added | [payload: AcceptableInputValue] |
removeTagEvent handler called when tag is removed | [payload: AcceptableInputValue] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
TagsInputInput
Props
| Prop | Type | Default |
|---|---|---|
placeholderThe placeholder character to use for empty tags input. | string | - |
autoFocusFocus on element when mounted. | boolean | - |
maxLengthMaximum number of character allowed. | number | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
TagsInputItem
Props
| Prop | Type | Default |
|---|---|---|
valuerequiredValue associated with the tags | AcceptableInputValue | - |
disabledWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
TagsInputItemDelete
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
TagsInputItemText
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Accessibility
There is no dedicated WAI-ARIA pattern for tags inputs. Reka UI renders the tags followed by a native text input, and handles the keyboard navigation between the input and the tags.
| Key | Description |
|---|---|
| Tab | Moves focus to the input. |
| Enter | When focus is on the input, adds the typed text as a tag. |
| Delete | When a tag is active, removes it and sets the next tag active. |
| Backspace | When a tag is active, removes it and sets the previous tag active. |
| ArrowRight | Sets the next tag active. |
| ArrowLeft | Sets the previous tag active. |
| Home | Sets the first tag active. |
| End | Sets the last tag active. |