TagGroup
A tag group is a focusable list of labels, categories, keywords, filters, or other items, with support for keyboard navigation, selection, and removal.
Content
TagGroup
follows the Collection Components API, accepting both static and dynamic collections. This example shows a dynamic collection, passing a list of objects to the items
prop, and a function to render the children. Items can be removed via the onRemove
event.
import {TagGroup, Tag} from './TagGroup';
import {useListData} from 'react-stately';
function Example() {
let list = useListData({
initialItems: [
{ id: 1, name: 'News' },
{ id: 2, name: 'Travel' },
{ id: 3, name: 'Gaming' },
{ id: 4, name: 'Shopping' }
]
});
return (
<TagGroup
label="Categories"
items={list.items}
onRemove={(keys) => list.remove(...keys)}
renderEmptyState={() => <div>No categories</div>}>
{(item) => <Tag>{item.name}</Tag>}
</TagGroup>
);
}
Links
Use the href
prop on a <Tag>
to create a link. See the client side routing guide to learn how to integrate with your framework.
import {TagGroup, Tag} from './TagGroup';
<TagGroup label="Photo categories">
<Tag href="https://en.wikipedia.org/wiki/Landscape_photography" target="_blank">Landscape</Tag>
<Tag href="https://en.wikipedia.org/wiki/Portrait_photography" target="_blank">Portrait</Tag>
<Tag href="https://en.wikipedia.org/wiki/Macro_photography" target="_blank">Macro</Tag>
<Tag href="https://en.wikipedia.org/wiki/Night_photography" target="_blank">Night</Tag>
<Tag href="https://en.wikipedia.org/wiki/Dualphotography" target="_blank">Dual</Tag>
<Tag href="https://en.wikipedia.org/wiki/Golden_hour_(photography)" target="_blank">Golden Hour</Tag>
</TagGroup>
Selection
Use the selectionMode
prop to enable single or multiple selection. The selected items can be controlled via the selectedKeys
prop, matching the id
prop of the items. Items can be disabled with the isDisabled
prop. See the selection guide for more details.
Current selection: