Tag group API
Import
Section titled “Import”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';Controlled/uncontrolled usage
Section titled “Controlled/uncontrolled usage”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.
import { Tag, TagGroup, type Selection, Stack } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [selectedKeys, setSelectedKeys] = useState<Selection>(() => new Set(['apple']));
return ( <Stack gap={32}> <TagGroup label="Favorite fruits (controlled)" selectionMode="multiple" selectedKeys={selectedKeys} onSelectionChange={setSelectedKeys} > <Tag id="apple">Apple</Tag> <Tag id="banana">Banana</Tag> <Tag id="cherry">Cherry</Tag> </TagGroup>
<TagGroup label="Favorite fruits (uncontrolled)" selectionMode="multiple" defaultSelectedKeys={['apple']}> <Tag id="apple">Apple</Tag> <Tag id="banana">Banana</Tag> <Tag id="cherry">Cherry</Tag> </TagGroup> </Stack> );}Accessibility notes
Section titled “Accessibility notes”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.
Collections
Section titled “Collections”TagGroup is a collection component. See our collection components guide to learn how to work with collections.
API reference
Section titled “API reference”TagGroup
Section titled “TagGroup”Displays a group of tags. Allows for selecting or removing tags.
- Ref<HTMLDivElement>
-
The
reftype for this component.
TagGroupProps<T extends CollectionItem = CollectionItem>
- boolean
isRequired
Section titled “ isRequired ” -
Whether the tag group is required.
- string
error
Section titled “ error ” -
The error message to display.
- 'medium' | 'large'
-
The size of the tags.
- () => ReactNode
renderEmptyState
Section titled “ renderEmptyState ” -
Provides content to display when there are no tags in the group.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
label
Section titled “ label ” -
The content to display as the label.
- string
aria-label
Section titled “ aria-label ” -
Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “ aria-labelledby ” -
Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “ aria-describedby ” -
Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “ aria-details ” -
Identifies the element (or elements) that provide a detailed, extended description for the object.
- string
description
Section titled “ description ” -
A description for the field. Provides a hint such as specific requirements for what to choose.
- (keys: Set<Key>) => void
onRemove
Section titled “ onRemove ” -
Handler that is called when a user deletes a tag.
- Iterable<T, any, any>
items
Section titled “ items ” -
Item objects in the collection.
- Iterable<Key, any, any>
disabledKeys
Section titled “ disabledKeys ” -
The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
- SelectionMode
selectionMode
Section titled “ selectionMode ” -
The type of selection that is allowed in the collection.
- 'all' | (Iterable<Key, any, any>)
selectedKeys
Section titled “ selectedKeys ” -
The currently selected keys in the collection (controlled).
- 'all' | (Iterable<Key, any, any>)
defaultSelectedKeys
Section titled “ defaultSelectedKeys ” -
The initial selected keys in the collection (uncontrolled).
- (keys: Selection) => void
onSelectionChange
Section titled “ onSelectionChange ” -
Handler that is called when the selection changes.
- ReactNode | ((item: T) => ReactNode)
children
Section titled “ children ” -
The contents of the collection.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
Displays a single tag within a tag group.
- Ref<HTMLDivElement>
-
The
reftype for this component.
TagProps
- StringLikeChildren
children *
Section titled “ children * ” -
The content to display as the label.
- ReactNode
iconStart
Section titled “ iconStart ” -
The icon to display at the start of the tag.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- Key
-
A unique id for the tag.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the tag is disabled.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.