PeakUI

TagGroup

A focusable list of selectable and removable tags

Usage

import {TagGroup} from "@peakui/react";

Anatomy

import {Description, Label, Tag, TagGroup} from "@peakui/react";

export default () => (
  <TagGroup selectionMode="single">
    <Label>Amenities</Label>
    <TagGroup.List>
      <Tag>
        Tag label
        <Tag.RemoveButton />
      </Tag>
    </TagGroup.List>
    <Description>Optional hint</Description>
  </TagGroup>
);

Examples

Sizes

size on the group scales every tag.

Variants

variant switches the tag background between default and surface.

Disabled State

isDisabled disables one tag; disabledKeys disables tags by id.

Selection Modes

selectionMode allows a single or multiple selected tags.

Controlled Selection

selectedKeys with onSelectionChange controls the selection from state.

With Prefix

Any element prefix renders before the label.

With Remove Button

onRemove renders a remove button in every tag automatically.

Render Function

render on the root replaces the rendered element.

Customization

Tailwind CSS

Global CSS

@layer components {
  .tag-group {
    @apply flex flex-col gap-2;
  }

  .tag-group__list {
    @apply flex flex-wrap gap-2;
  }

  .tag {
    @apply rounded-full px-3 py-1;
  }

  .tag__remove-button {
    @apply ml-1;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The TagGroup component uses these CSS classes (view source styles and tag.css):

Base Classes

  • .tag-group - Base tag group container
  • .tag-group__list - Container for the list of tags
  • .tag - Base tag styles
  • .tag__remove-button - Remove button trigger

Size Classes

  • .tag--sm - Small size tag
  • .tag--md - Medium size tag (default)
  • .tag--lg - Large size tag

Variant Classes

  • .tag--default - Default variant
  • .tag--surface - Surface variant with surface background

Field Slot Classes

  • .tag-group [slot="description"] - Description slot styles
  • .tag-group [data-slot="description"] - Description slot styles, data-attribute form
  • .tag-group [slot="errorMessage"] - Error message slot styles
  • .tag-group [data-slot="error-message"] - Error message slot styles, data-attribute form

Slots

  • [data-slot="tag-group"] - The tag group root
  • [data-slot="tag-group-list"] - The list of tags
  • [data-slot="tag"] - A single tag
  • [data-slot="tag-remove-button"] - The remove button inside a tag

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered="true"] on the tag
  • Focus: :focus-visible or [data-focus-visible] on the tag
  • Selected: [data-selected="true"] or [aria-selected="true"] on the tag
  • Disabled: [data-disabled="true"] or [aria-disabled="true"] on the tag

API Reference

TagGroup

PropTypeDefaultDescription
selectionMode"none" | "single" | "multiple""none"The type of selection that is allowed
selectedKeysSelection-The currently selected keys (controlled)
defaultSelectedKeysSelection-The initial selected keys (uncontrolled)
onSelectionChange(keys: Selection) => void-Handler called when the selection changes
disabledKeysIterable<Key>-Keys of disabled tags
isDisabledboolean-Whether the tag group is disabled
onRemove(keys: Set<Key>) => void-Handler called when tags are removed
size"sm" | "md" | "lg""md"Size of the tags in the group
variant"default" | "surface""default"Visual variant of the tags
classNamestring-Additional CSS classes
childrenReactNode-TagGroup content
renderDOMRenderFunction<"div", undefined>-Replaces the rendered <div> with a custom render function
...restReact Aria TagGroup attributes-Focus, keyboard navigation and DOM attributes of the underlying React Aria TagGroup

TagGroup.List

PropTypeDefaultDescription
itemsIterable<T>-The items to display in the tag list
renderEmptyState(props: TagListRenderProps) => ReactNode-Function to render when the list is empty
classNamestring-Additional CSS classes
childrenReactNode | ((item: T) => ReactElement)-TagList content or item render function
renderDOMRenderFunction<"div", TagListRenderProps>-Replaces the rendered <div> with a custom render function
...restReact Aria TagList attributes-Collection and DOM attributes of the underlying React Aria TagList

Name the group with aria-label or a Label; without one the grid has no accessible name.

Tag

PropTypeDefaultDescription
idKey-The unique identifier for the tag
textValuestring-A string representation of the tag's content, used for accessibility; falls back to the first string child
isDisabledboolean-Whether the tag is disabled
classNamestring-Additional CSS classes
childrenReactNode | ((renderProps: TagRenderProps) => ReactNode)-Tag content or render function
renderDOMRenderFunction<"div", undefined>-Replaces the rendered <div> with a custom render function
...restReact Aria Tag attributes-Selection, hover, focus and press attributes of the underlying React Aria Tag

size and variant are inherited from the parent TagGroup and cannot be set on individual tags.

Tag.RemoveButton

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode-Custom remove button content (defaults to close icon)
...restReact Aria Button attributes-Press and DOM attributes of the underlying React Aria Button

When onRemove is provided to TagGroup, a remove button renders automatically; a Tag.RemoveButton passed as a child of Tag replaces it.

Render Props

When the Tag children is a function, it receives these values:

PropTypeDescription
isSelectedbooleanWhether the tag is selected
isDisabledbooleanWhether the tag is disabled
isHoveredbooleanWhether the tag is hovered
isPressedbooleanWhether the tag is pressed
isFocusedbooleanWhether the tag is focused
isFocusVisiblebooleanWhether the tag has keyboard focus
allowsRemovingbooleanWhether the tag group allows the tag to be removed

On this page