TagSelector
TagSelector - A multi-select tag component with search, create, edit, delete, and reorder capabilities.
Usage
import { TagColor, TagData, TagSelector, TagSelectorContent, TagSelectorContextValue, TagSelectorItem, TagSelectorList, TagSelectorProps, TagSelectorSearch, TagSelectorTrigger, TagSelectorTriggerRenderProps, useTagSelectorContext } from "@desk/ui/components/tag-selector";Best practices
The CRUD affordances are gated —
onCreateTag/onEditTag/onDeleteTag/onReorderdo nothing unless you also set the matchingallowCreate/allowManage/allowReorderflag.value/onChangecarry the selectedTagData[]and are required —TagSelectoris controlled; supply the full option set viatags.A custom
triggerrender-prop is wrapped inPopoverTrigger asChild, so return a single element that forwards its ref/props (e.g. aButton).Use
singleSelectwhen only one tag may be chosen; for a fixed, non-editable list preferCombobox/multi-Selectand reserveTagSelectorfor managing the tag set itself.
Props
TagSelector
| Prop | Type | Default | Description |
|---|---|---|---|
| allowCreate | boolean | Allow creating new tags | |
| allowManage | boolean | Allow editing/deleting tags | |
| allowReorder | boolean | Allow reordering tags | |
| className | string | ||
| colorPalette | TagColor[] | Available colors for the color picker | |
| coverTrigger | boolean | Whether the popover overlaps the trigger instead of appearing below it | |
| disabled | boolean | Disabled state | |
| emptyMessage | string | Empty state message | |
| maxVisibleTags | number | Cap how many selected chips the trigger renders. When set and the selection
exceeds it, only the first N chips show, followed by a | |
| onChange | (tags: TagData[]) => void | Called when selection changes | |
| onCreateTag | (label: string, color?: TagColor) => Promise<TagData> | Called when a new tag is created | |
| onDeleteTag | (id: string) => Promise<void> | Called when a tag is deleted | |
| onEditTag | (id: string, newLabel: string, color?: TagColor) => Promise<void> | Called when a tag is edited | |
| onOpenChange | (open: boolean) => void | Called when open state changes | |
| onReorder | (tags: TagData[]) => void | Called when tags are reordered | |
| onSearch | (query: string) => Promise<TagData[]> | Called when tags list should be refetched (e.g., on search) | |
| open | boolean | Controlled open state | |
| reorderAnnouncements | Announcements | Override the drag-and-drop screen-reader announcements used while reordering tags. Follows | |
| placeholder | string | Placeholder text | |
| searchPlaceholder | string | Search input placeholder | |
| showColorPicker | boolean | Show color picker swatches when creating/editing tags | |
| singleSelect | boolean | Single-select mode: only one tag can be selected at a time | |
| size | import("../pill").PillSize | Component size | |
| tags | TagData[] | All available tags | |
| trigger | (props: TagSelectorTriggerRenderProps) => React.ReactNode | Custom trigger render function. When provided, replaces the default trigger. | |
| truncateChips | boolean | Opt-in per-chip truncation. Long labels ellipsize (CSS | |
| value | TagData[] | Currently selected tags | |
| wrapTags | boolean | Whether tags wrap (true) or scroll horizontally (false) |
TagSelectorContent
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | ||
| className | string |
TagSelectorItem
| Prop | Type | Default | Description |
|---|---|---|---|
| selected | boolean | Whether this tag is selected | |
| tag | TagData | The tag data |
TagSelectorList
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ||
| emptyMessage | string | Custom empty state message |
TagSelectorSearch
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ||
| placeholder | string | Placeholder text for search input |
TagSelectorTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ||
| placeholder | string | Placeholder text when no tags selected |
Also exports
- type
TagColor - interface
TagData - interface
TagSelectorContextValue - interface
TagSelectorProps - interface
TagSelectorTriggerRenderProps - const
useTagSelectorContext
Composition
Builds on
Dot, DropdownMenu, Icon, Input, Pill, Popover, ScrollArea, ScrollFade, Tag