Skip to content

CdsTag

A tag is a compact label next to an object: the status of a request, a product category, a selected filter. It takes a color from the palette, carries an icon or an avatar, can be closed with a cross and can work as a link.

Storybook GitLab Figma
Test coverage: 97% — good coverage
API in specs
41 / 41 props, events, slots and exposed members with a test
Test cases
67 unit · 0 browser
Known bugs
5 pinned by an it.fails test
Code coverage
96.5% lines · 97.4% branches measured in v4.0.0-alpha.13
A11y (axe)
2 recommendations in 13 stories measured in v4.0.0-alpha.11

To build a toggle or a filter with selection out of tags, take CdsTagGroup. For a counter or a dot indicator on top of another element use CdsBadge, and trigger actions with CdsButton — a tag only labels.

Anatomy ​

A tag consists of a container and content areas: prepend and append carry an icon or an avatar, the text lives in the center, and the close button appears with closable.

Variations ​

Colors ​

The color prop paints the tag in one of the 11 palette aliases; without it the tag stays neutral gray. The text color can be overridden with text-color when needed. The disabled prop swaps the tag colors for the service colors of the disabled state and removes the reaction to clicks.

Sizes ​

The size prop offers five sizes from xs to xl. The default size is md.

Shape ​

The pill prop rounds the corners completely — this shape emphasizes that the label stands on its own and looks good in a tag cloud.

Icons and avatars ​

The prepend-icon and append-icon props add an icon before and after the text, prepend-avatar and append-avatar add a round avatar. The size of the icon and the avatar follows the size of the tag.

Slots ​

Slots replace the content coming from props when you need full control over the markup.

SlotDescription
defaultContent of the tag. Replaces the text from text
prependContent before the text. Replaces prepend-icon / prepend-avatar
appendContent after the text. Replaces append-icon / append-avatar
closeContent of the close button. Replaces the icon from close-icon
filterContent of the selection indicator in a group. Replaces the icon from filter-icon

Pass href (or to with a RouteLocationRaw object from vue-router) and the tag renders as an a tag: it gets a cursor, keyboard focus and navigation on Enter, keeping the look of a tag.

Closing ​

The closable prop (or its alias removable) adds a close button. A click on it hides the tag and emits the click:close event, and the visibility can be controlled from the outside through v-model. The close-icon prop changes the icon of the button, close-label changes the accessible label.

Selection in a group ​

Inside CdsTagGroup a tag becomes a toggle: value sets its value in the group, the selected state is marked with the cds-tag--selected class, and the group:selected event reports the change of selection. With filter the selected tag gets an indicator — filter-icon changes the icon, the filter slot changes the whole markup. The default slot exposes isSelected, toggle and select — a handy base for your own tag markup.

The color of the selected tag comes from active-color: without it the group itself paints the selection with the brand color, and color stays the color of the unselected tag.

Guidelines ​

Scenarios ​

Selected filters ​

Applied search filters read well as a row of closable tags: each tag removes its own filter on click:close, and the neighboring tertiary button resets everything at once.

Record statuses ​

In lists and tables a colored tag shows the state of a record instantly. Assign colors to statuses once: green — success, lemon — pending, red — rejection, neutral — draft. The compact size="sm" does not compete with the text of the row.

Adding labels ​

An input field together with tags makes a label editor: Enter adds a new label, the cross (closable + click:close) removes an extra one. Duplicates are cut off before they get into the list.

API ​

Props

NameTypeDefaultDescription
activeClassstring | undefined—CSS class applied to the active (selected) link tag.
activeColorstring | undefined—Color of the component in its active state
appendAvatarstring | undefined—Avatar displayed after (to the right of) the tag content.
appendIconIconValue | undefined—Icon displayed after (to the right of) the tag content.
closableboolean | undefined—Adds a close button that hides the tag.
closeIconIconValue | undefined'remove'Icon of the close button.
closeLabelstring | undefined'$cds.close'Accessible label (aria-label) for the close button.
colorstring | undefined—Component color
contentstring | number | undefined—Content displayed in the component.
disabledboolean | null | undefinednullDisabled state
draggableboolean | undefined—Makes the tag draggable (native drag-and-drop).
exactboolean | undefined—If true, the active state applies only on an exact route match
filterboolean | undefined—Shows the selection indicator icon when the tag is used inside a group (CdsTagGroup).
filterIconIconValue | undefined'check'Icon of the selection indicator (relevant together with filter).
hrefstring | undefined—The href attribute of the link. When set, the component behaves as a regular link
labelboolean | undefined—Applies the “label” style with a smaller corner radius.
linkboolean | undefined—Gives the tag the styles and the behavior of a link.
modelValueboolean | undefinedtrueVisibility of the tag (v-model). When false the tag is not rendered.
pillboolean | undefined—Makes the corners of the tag fully rounded.
prependAvatarstring | undefined—Avatar displayed before (to the left of) the tag content.
prependIconIconValue | undefined—Icon displayed before (to the left of) the tag content.
removableboolean | undefined—Adds a remove button (alias for closable).
replaceboolean | undefined—If true, navigation replaces the current history entry instead of pushing a new one
selectedClassstring | undefined—CSS class applied in the selected state
sizenumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined'md'Size of the component
tagstring | JSXComponent<any> | undefined'span'Custom HTML tag or component to render
textstring | number | undefined—Text displayed in the component.
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
toLinkTo | undefined—Target route or route location object for RouterLink. When set, the component behaves as a RouterLink
valueany—Value of the component within the group

Events

NameTypeDescription
click[e: MouseEvent | KeyboardEvent]Click on the tag (with a mouse or from the keyboard).
click:close[e: MouseEvent]Click on the close button of the tag.
group:selected[value: { value: boolean; }]Change of the tag selection state inside a group.
update:modelValue[value: boolean]Change of the tag visibility (v-model).

Slots

NameTypeDescription
appendanyContent after the main content (in place of the append icon/avatar).
closeanyCustom content of the close button.
default{ isSelected: boolean | undefined; selectedClass: boolean | (string | undefined)[] | undefined; select: ((value: boolean) => void) | undefined; toggle: (() => void) | undefined; value: unknown; disabled: boolean; }Default content of the tag. The slot props expose the group state (selection, toggling).
filteranyCustom content of the selection indicator (relevant together with filter).
labelanyContent of the tag label.
prependanyContent before the main content (in place of the prepend icon/avatar).