Components
TagSelector
Tag-based multi-select compound component with built-in search and CRUD
Overview
TagSelector is a compound component for tag-based multi-selection. It has built-in search, create, edit, and delete functionality.
Features
- Tag search and filtering
- Inline tag creation
- Tag edit/delete
- Keyboard navigation
- Close on outside click
- Customizable trigger
- TypeScript support
Basic Usage
Anatomy
Root holds the data and the handlers. Inside it go Trigger (what opens the selector) and Content, which usually holds Search and List. See the full example under Basic Usage.
API Reference
Root
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | ReactNode | - | Yes | Trigger·Content(Search·List) |
tags | TagType[] | - | Yes | Tags to choose from |
selectedTags | TagType[] | - | Yes | The chosen tags |
maxTagLength | number | 100 | No | Maximum length of a new tag name |
onAddTag | (tagId: string) => Promise<void> | - | Yes | Called when a tag is chosen |
onRemoveTag | (tagId: string) => Promise<void> | - | Yes | Called when a chosen tag is removed (pressed again in the list, or its × in the search box) |
onCreateTag | (data: Partial<OmittedTag>) => Promise<string> | - | Yes | Called to create a tag from the search text. Returns the new id |
onDeleteTag | (tagId: string) => Promise<void> | - | Yes | Called to delete a tag |
onUpdateTag | (tagId: string, data: Partial<OmittedTag>) => Promise<void> | - | Yes | Called to change a tag's name or color |
Trigger
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | ReactNode | - | Yes | What opens the selector |
asChild | boolean | - | No | Puts the trigger behavior (role="button", tabIndex=0, Enter and Space) on the child instead of a wrapper |
Data Attributes: data-state: "open" | "closed"
Content
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | ReactNode | - | No | Usually Search and List |
className | string | - | No | Extra CSS class |
Search
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
placeholder | string | 'Search tags...' | No | Placeholder of the search input |
maxLength | number | '100' | No | Maximum length of the search text |
List
Renders the filtered tag list.
No props.
Specification
base
| 상태 | 요소 | 속성 | 값 |
|---|---|---|---|
| enabled | content | width | 296px토큰 아님 — no sizing token scale |
| enabled | content | maxHeight | 400px토큰 아님 — no sizing token scale |
| enabled | content | padding | $size.space.200 |
| enabled | content | gap | $size.space.200 |
| enabled | content | backgroundColor | $color.background.default.default |
| enabled | content | borderWidth | $size.stroke.border |
| enabled | content | borderColor | $color.border.default.default |
| enabled | content | borderRadius | $size.radius.200 |
| enabled | search | padding | $size.space.200 |
| enabled | search | gap | $size.space.200 |
| enabled | search | borderRadius | $size.radius.100 |
| enabled | search | backgroundColor | $color.background.default.secondary |
| enabled | searchInput | typography | $text.bodySmall |
| enabled | searchInput | color | $color.text.default.default |
| enabled | item | gap | $size.space.100 |
| enabled | item | paddingRight | $size.space.200 |
| enabled | item | borderRadius | $size.radius.200 |
| enabled | selectButton | paddingX | $size.space.200 |
| enabled | selectButton | paddingY | $size.space.100 |
| enabled | selectButton | gap | $size.space.200 |
| enabled | selectButton | borderRadius | $size.radius.200 |
| enabled | editButton | opacity | 0토큰 아님 — opacity keeps it reachable with Tab while hidden |
| hover | item | backgroundColor | $color.background.default.defaultHover |
| hover | editButton | opacity | 1토큰 아님 — show |
| selected | check | color | $color.icon.default.default |
| focus | search | strokeWidth | $size.stroke.focus |
| focus | search | strokeColor | $color.border.brand.default |
| focus | editButton | opacity | 1토큰 아님 — show |
Accessibility
Keyboard Interactions
| Key | Action |
|---|---|
Tab | Moves search → each tag row → that row's edit button |
Enter / Space (row) | Toggles the tag. Focus returns to the search box to keep typing |
Enter (search) | Creates a new tag from the search text |
Backspace (search) | Removes the last selected tag when the search is empty |
Escape (search) | Clears the search text |
ARIA
- Trigger:
aria-expanded,aria-haspopup="dialog" - List:
ullabelled "Tags". Each row is a toggle button witharia-pressed; selected rows also show a check icon - Edit button: named
Edit <tag name>, witharia-expandedwhile the editor is open. It is hidden withopacity(notdisplay) until the row is hovered or focused, soTabstill reaches it
Custom API
useTagSelectorContext
What the hook returns:
export type TagSelectorContextValue = {
isOpen: boolean
searchTerm: string
selectedTags: TagType[]
filteredTags: TagType[]
canCreateNew: boolean
previewColor: TagColor
triggerRef: RefObject<HTMLElement | null>
contentRef: RefObject<HTMLDivElement | null>
inputRef: RefObject<HTMLInputElement | null>
setIsOpen: (open: boolean) => void
setSearchTerm: (term: string) => void
selectTag: (tag: TagType) => Promise<void>
removeTag: (tagId: string) => Promise<void>
createTag: () => Promise<void>
deleteTag: (tagId: string) => Promise<void>
updateTag: (tagId: string, data: Partial<OmittedTag>) => Promise<void>
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void
}