useTagGroup

Provides the behavior and accessibility implementation for a tag group component. A tag group is a focusable list of labels, categories, keywords, filters, or other items, with support for keyboard navigation, selection, and removal.

Music genres
Rock
Jazz
Pop
Classical
EDM
Example
TagGroup.tsx
TagGroup.css
import {Tag, TagGroup} from './TagGroup';

<TagGroup
  label="Music genres"
  onAction={key => alert(`Clicked ${key}`)}
>
  <Tag id="rock">Rock</Tag>
  <Tag id="jazz">Jazz</Tag>
  <Tag id="pop">Pop</Tag>
  <Tag id="classical">Classical</Tag>
  <Tag id="edm">EDM</Tag>
</TagGroup>

API

TravelingGrid rowGrid cellTag labelHikingRemove buttonTag groupCategoriesGroup label
<TagGroup>
  <Label />
  <TagList>
    <Tag>
      <SelectionIndicator />
      <Button slot="remove" />
    </Tag>
  </TagList>
  <Text slot="description" />
  <Text slot="errorMessage" />
</TagGroup>
useListState<T>(props: <T>): <T>useTagGroup<T>( props: <T>, state: <T>, ref: <HTMLElementnull> ): useTag<T>( props: <T>, state: <T>, ref: <FocusableElementnull> ):

ListState

NameType
collection<<T>>

A collection of items in the list.

selectionManager

A selection manager to read and update multiple selection state.

disabledKeysSet<Key>

A set of items that are disabled.

AriaTagGroupProps

NameType
children<T>

The contents of the collection.

itemsIterable<T>

Item objects in the collection.

selectionMode

The type of selection that is allowed in the collection.

selectionBehavior

How multiple selection should behave in the collection.

selectedKeys'all'Iterable<Key>

The currently selected keys in the collection (controlled).

defaultSelectedKeys'all'Iterable<Key>

The initial selected keys in the collection (uncontrolled).

onSelectionChange(keys: ) => void

Handler that is called when the selection changes.

disabledKeysIterable<Key>

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

disallowEmptySelectionboolean

Whether the collection allows empty selection.

shouldSelectOnPressUpboolean

Whether selection should occur on press up instead of press down.

escapeKeyBehavior'clearSelection''none'

Whether pressing the escape key should clear selection in the TagGroup or not.

Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually.

TagGroupAria

NameType
errorMessagePropsDOMAttributes
Props for the tag group error message element, if any.
descriptionPropsDOMAttributes
Props for the tag group description element, if any.
labelPropsDOMAttributes
Props for the tag group's visible label (if any).
gridPropsDOMAttributes
Props for the tag grouping element.

AriaTagProps

NameType
item<T>

An object representing the tag. Contains all the relevant information that makes up the tag.

TagAria

NameType
hasActionboolean
Whether the item has an action, dependent on onAction, disabledKeys, and disabledBehavior. It may also change depending on the current selection state of the list (e.g. when selection is primary). This can be used to enable or disable hover styles or other visual indications of interactivity.
allowsSelectionboolean
Whether the item may be selected, dependent on selectionMode, disabledKeys, and disabledBehavior.
isDisabledboolean
Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may not be focused. Dependent on disabledKeys and disabledBehavior.
isFocusedboolean
Whether the item is currently focused.
isSelectedboolean
Whether the item is currently selected.
isPressedboolean
Whether the item is currently in a pressed state.
allowsRemovingboolean
Whether the tag can be removed.
removeButtonProps
Props for the tag remove button.
gridCellPropsDOMAttributes
Props for the tag cell element.
rowPropsDOMAttributes
Props for the tag row element.