Components
Tag Group
A group of colorful tags that can be selected, removed and navigated with the keyboard.
Source code
Click to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.
Installation
To use the tag group as a field inside a Vee-Validate form, see VeeTagGroup.
Tag Group vs. Badge vs. Tags Input
| Tag Group | Badge | Tags Input | |
|---|---|---|---|
| Purpose | A list of tags the user can focus, select or remove | A static label | An input where the user types new tags |
| Keyboard | Arrow keys, Home/End, typeahead, Delete | None | Typing, arrow keys, Backspace |
| Selection | None, single or multiple | No | No |
| Colors | 30 colors, 4 variants | 30 colors, 12 variants | Neutral |
Use a tag group for filters, choice chips and removable lists. Use a badge for a status that does nothing, and a tags input when users create the tags themselves.
Usage
The group renders a grid that needs an accessible name, so always pass an aria-label (or aria-labelledby). Set color, variant, size and shape on the group to style every tag at once, and override any of them on a single tag. The text of a tag is the default slot, which is also used for typeahead.
<template>
<UiTagGroup v-model="selected" aria-label="Topics" selection-mode="multiple" color="indigo">
<UiTagGroupItem value="vue" icon="logos:vue">Vue</UiTagGroupItem>
<UiTagGroupItem value="nuxt" color="green" removable>Nuxt</UiTagGroupItem>
</UiTagGroup>
</template>
@remove. The group does not delete anything itself, it tells you which values were removed and you update your own list. Without the listener, removable buttons and the Delete key do nothing.Examples
Basic
A removable list. removable shows the remove button of a tag and the group emits remove with the values to delete. Focus a tag and press Delete or Backspace to remove it too.
Click the x, or focus a tag and press Delete or Backspace.
Colors
There are 30 colors: primary, the full Tailwind palette (red to rose, slate, gray, zinc, neutral, stone and the newer taupe, mauve, mist and olive) and the error, warning and success aliases. Every color has light and dark styles. They are shared with UiBadge through ~/utils/badge-colors, which also exports the badgeColors array.
Variants
soft (default) is a tinted pill, solid is filled, outline only draws the border and modern is a neutral card where the color is used for the dot.
soft
solid
outline
modern
Sizes
Use size with sm, md (default) or lg.
Shapes
Use shape="pill" (default) or shape="rounded".
Icons
icon renders an icon before the text and trailing-icon one after it. For anything else use the leading and trailing slots.
Dots
The modern variant shows a colored dot by default. Add dot to show one on any other variant (an avatar or icon replaces the default dot of modern).
Avatars
Use avatar to show an image before the text.
Single selection
Set selection-mode="single" and bind a value with v-model. Selected tags show a check mark and a stronger ring. Press Escape to clear the selection, or add disallow-empty-selection to prevent it.
Selected: M
Multiple selection
With selection-mode="multiple" the v-model is an array. Space and Enter toggle the focused tag.
Selected: code
Add and remove
A tag group can be selectable and removable at once. When the focused tag is selected, Delete removes every selected tag.
Select several tags, then press Delete or Backspace to remove them together.
Custom content
The leading, trailing and delete slots receive { selected, disabled }, so the content can react to the state of the tag.
Disabled
Disable the whole group with disabled, or single tags. Disabled tags are skipped by keyboard navigation.
Props
TagGroup
| Prop | Type | Default | Description |
|---|---|---|---|
v-model | T | T[] | The selected tag(s). An array when selection-mode is multiple. | |
default-value | T | T[] | Initial selection when uncontrolled. | |
selection-mode | "none" | "single" | "multiple" | "none" | Whether tags can be selected. |
disallow-empty-selection | boolean | false | Prevent the user from deselecting the last selected tag. |
escape-key-behavior | "clearSelection" | "none" | "clearSelection" | What the Escape key does. |
color | TagGroupColor | Default color of the tags. | |
variant | "soft" | "solid" | "outline" | "modern" | Default variant of the tags. | |
size | "sm" | "md" | "lg" | Default size of the tags. | |
shape | "pill" | "rounded" | Default shape of the tags. | |
by | string | ((a: T, b: T) => boolean) | Property name or comparator used to compare object values. | |
loop | boolean | true | Wrap keyboard navigation from the last tag to the first and vice versa. |
disabled | boolean | Prevents interaction with the group and all of its tags. | |
dir | "ltr" | "rtl" | Reading direction. | |
aria-label | string | Accessible name of the group. Required unless aria-labelledby is used. |
The group emits update:modelValue and remove. The slot receives modelValue.
TagGroupItem
| Prop | Type | Default | Description |
|---|---|---|---|
value | T | The unique value of the tag. Required. | |
color | TagGroupColor | group, then "gray" | Color of the tag. |
variant | TagGroupVariant | group, then "soft" | Variant of the tag. |
size | TagGroupSize | group, then "md" | Size of the tag. |
shape | TagGroupShape | group, then "pill" | Shape of the tag. |
icon | string | Icon shown before the text. | |
trailing-icon | string | Icon shown after the text. | |
dot | boolean | false | Show a colored dot before the text. |
avatar | string | Image shown before the text. | |
removable | boolean | false | Show the remove button. The group must listen to @remove. |
delete-icon | string | "lucide:x" | Icon of the remove button. |
show-check | boolean | true | Replace the leading content with a check mark while selected. |
disabled | boolean | Prevents interaction with the tag. | |
text-value | string | Plain text used for typeahead and the accessible name. Defaults to the text of the tag. |
The leading content is chosen in this order: check mark (when selected), dot, avatar, icon. The modern variant shows a dot by default, unless an avatar or icon is set.
| Slot | Props | Description |
|---|---|---|
default | { selected, disabled } | The text of the tag. Defaults to the value. |
leading | { selected, disabled } | Content before the text. |
trailing | { selected, disabled } | Content after the text. |
delete | { selected, disabled } | Replaces the remove button. Only rendered when removable. |
TagGroupItemDelete
| Prop | Type | Default | Description |
|---|---|---|---|
icon | string | "lucide:x" | Icon shown inside the button. |
aria-label | string | "Remove" | Override to translate the accessible name. The tag name is appended. |
Accessibility
The group has the grid role (or group while it is empty) and every tag is a row. Focus moves with a roving tabindex, so the whole group is a single tab stop. Selected tags set aria-selected, and additions to the group are announced politely while it has focus.
| Key | Description |
|---|---|
Tab | Moves focus into the group, then to the remove button of the focused tag, then out. |
ArrowRight / ArrowDown | Moves to the next tag. |
ArrowLeft / ArrowUp | Moves to the previous tag. |
Home / End | Moves to the first or last tag. |
Space / Enter | Toggles the focused tag when the group is selectable. |
Delete / Backspace | Removes the focused tag, or all selected tags if it is selected. Needs @remove. |
Escape | Clears the selection. |
| Any character | Moves to the next tag that starts with the typed text. |