A list of tags
import { TagGroup } from "@senvenli/react/selection";
export default function Example() {
return (
<TagGroup
label="Included in your plan"
items={[
{ id: "api", label: "API access", icon: "code" },
{ id: "sso", label: "Single sign-on", icon: "key-round" },
{ id: "audit", label: "Audit log", icon: "scroll-text" },
{ id: "support", label: "Priority support" },
]}
/>
);
}import { TagGroup } from "@senvenli/react/selection";Examples
Removable
Active filters: each tag has a remove button, and the group says when none are left.import { TagGroup, type TagItem } from "@senvenli/react/selection";
import { useState } from "react";
export default function Example() {
const [filters, setFilters] = useState<TagItem[]>([
{ id: "status", label: "Status: Paid" },
{ id: "customer", label: "Customer: Ada Lovelace" },
{ id: "period", label: "Last 30 days" },
]);
return (
<TagGroup
label="Active filters"
items={filters}
onRemove={(keys) => setFilters((current) => current.filter((filter) => !keys.includes(filter.id)))}
emptyState="No filters. Showing every invoice."
/>
);
}Selectable
Tags that toggle, for picking several of a few.import { TagGroup } from "@senvenli/react/selection";
import { useState } from "react";
export default function Example() {
const [days, setDays] = useState<(string | number)[]>(["mon", "wed"]);
return (
<TagGroup
label="Delivery days"
description={`${days.length} of 5 days selected.`}
selectionMode="multiple"
selectedKeys={days}
onSelectionChange={setDays}
items={[
{ id: "mon", label: "Monday" },
{ id: "tue", label: "Tuesday" },
{ id: "wed", label: "Wednesday" },
{ id: "thu", label: "Thursday" },
{ id: "fri", label: "Friday" },
]}
/>
);
}Guidelines
When to use it
- Showing or picking keywords, features or active filters.
Use something else when
- The tag is an item's status. Badge
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow keys | Moves between tags. |
| Delete, Backspace | Removes the focused tag. |
Built in
- Groups of three or more removable tags offer "Clear all".
You provide
- A label for the group.
API reference
TagGroup
| Prop | Type | Default | Description |
|---|---|---|---|
labelRequired | React.ReactNode | – | |
itemsRequired | readonly TagItem[] | – | |
onRemove | (keys: Key[]) => void | – | Makes tags removable (active filters); called with the keys removed. |
selectionMode | "single" | "multiple" | – | Makes tags selectable (features, filters). |
selectedKeys | readonly Key[] | – | |
defaultSelectedKeys | readonly Key[] | – | |
onSelectionChange | (keys: Key[]) => void | – | |
description | React.ReactNode | – | |
errorMessage | React.ReactNode | – | |
emptyState | React.ReactNode | – | What to show when there are no tags ("No filters"). |
labelRequiredReact.ReactNodeitemsRequiredreadonly TagItem[]onRemove(keys: Key[]) => voidMakes tags removable (active filters); called with the keys removed.
selectionMode"single" | "multiple"Makes tags selectable (features, filters).
selectedKeysreadonly Key[]defaultSelectedKeysreadonly Key[]onSelectionChange(keys: Key[]) => voiddescriptionReact.ReactNodeerrorMessageReact.ReactNodeemptyStateReact.ReactNodeWhat to show when there are no tags ("No filters").