Skip to content

Tag group API

Cimpress UI exports two tag-related components:

  • TagGroup: container component that groups related tags together, providing a label, description, error handling, and selection and removal.
  • Tag: component to display a tag within a tag group, optionally with an icon.
import { TagGroup, Tag } from '@cimpress-ui/react';

This component can be used in a controlled or uncontrolled way.

In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.

In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.

TagGroup requires a textual label to remain accessible to assistive technologies. See our accessibility guide for more details.

TagGroup is a single tab stop within the page’s tab order. Use the Tab key to navigate to the group, and the arrow keys to navigate between tags within the group. Use the Backspace or Delete key to remove tags from the group.

TagGroup is a collection component. See our collection components guide to learn how to work with collections.

Displays a group of tags. Allows for selecting or removing tags.

See tag group usage guidelines.

ref Ref<HTMLDivElement>

The ref type for this component.

TagGroupProps<T extends CollectionItem = CollectionItem>
isRequired boolean

Whether the tag group is required.

error string

The error message to display.

size 'medium' | 'large'

The size of the tags.

renderEmptyState () => ReactNode

Provides content to display when there are no tags in the group.

id string

The element's unique identifier. See MDN.

data-cim-style-root boolean

Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

UNSAFE_className string

Sets the CSS className for the element. Only use as a last resort. Use style props instead.

See styling guide.

UNSAFE_style CSSProperties

Sets the CSS style for the element. Only use as a last resort. Use style props instead.

See styling guide.

label string

The content to display as the label.

aria-label string

Defines a string value that labels the current element.

aria-labelledby string

Identifies the element (or elements) that labels the current element.

aria-describedby string

Identifies the element (or elements) that describes the object.

aria-details string

Identifies the element (or elements) that provide a detailed, extended description for the object.

description string

A description for the field. Provides a hint such as specific requirements for what to choose.

onRemove (keys: Set<Key>) => void

Handler that is called when a user deletes a tag.

items Iterable<T, any, any>

Item objects in the collection.

disabledKeys Iterable<Key, any, any>

The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.

selectionMode SelectionMode

The type of selection that is allowed in the collection.

selectedKeys 'all' | (Iterable<Key, any, any>)

The currently selected keys in the collection (controlled).

defaultSelectedKeys 'all' | (Iterable<Key, any, any>)

The initial selected keys in the collection (uncontrolled).

onSelectionChange (keys: Selection) => void

Handler that is called when the selection changes.

children ReactNode | ((item: T) => ReactNode)

The contents of the collection.

StyleProps
margin Responsive<Spacing | "auto">

The amount of margin applied to all edges of this component.

marginX Responsive<Spacing | "auto">

The amount of margin applied to the left and right edges of this component. Takes priority over margin.

marginY Responsive<Spacing | "auto">

The amount of margin applied to the top and bottom edges of this component. Takes priority over margin.

marginTop Responsive<Spacing | "auto">

The amount of margin applied to the top edge of this component. Takes priority over marginY and margin.

marginRight Responsive<Spacing | "auto">

The amount of margin applied to the right edge of this component. Takes priority over marginX and margin.

marginBottom Responsive<Spacing | "auto">

The amount of margin applied to the bottom edge of this component. Takes priority over marginY and margin.

marginLeft Responsive<Spacing | "auto">

The amount of margin applied to the left edge of this component. Takes priority over marginX and margin.

Displays a single tag within a tag group.

See tag group usage guidelines.

ref Ref<HTMLElement>

The ref type for this component.

TagProps
children * StringLikeChildren

The content to display as the label.

iconStart ReactNode

The icon to display at the start of the tag.

data-cim-style-root boolean

Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

UNSAFE_className string

Sets the CSS className for the element. Only use as a last resort. Use style props instead.

See styling guide.

UNSAFE_style CSSProperties

Sets the CSS style for the element. Only use as a last resort. Use style props instead.

See styling guide.

id Key

A unique id for the tag.

isDisabled boolean

Whether the tag is disabled.

StyleProps
margin Responsive<Spacing | "auto">

The amount of margin applied to all edges of this component.

marginX Responsive<Spacing | "auto">

The amount of margin applied to the left and right edges of this component. Takes priority over margin.

marginY Responsive<Spacing | "auto">

The amount of margin applied to the top and bottom edges of this component. Takes priority over margin.

marginTop Responsive<Spacing | "auto">

The amount of margin applied to the top edge of this component. Takes priority over marginY and margin.

marginRight Responsive<Spacing | "auto">

The amount of margin applied to the right edge of this component. Takes priority over marginX and margin.

marginBottom Responsive<Spacing | "auto">

The amount of margin applied to the bottom edge of this component. Takes priority over marginY and margin.

marginLeft Responsive<Spacing | "auto">

The amount of margin applied to the left edge of this component. Takes priority over marginX and margin.