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

PropTypeDefaultRequiredDescription
childrenReactNode-YesTrigger·Content(Search·List)
tagsTagType[]-YesTags to choose from
selectedTagsTagType[]-YesThe chosen tags
maxTagLengthnumber100NoMaximum length of a new tag name
onAddTag(tagId: string) => Promise<void>-YesCalled when a tag is chosen
onRemoveTag(tagId: string) => Promise<void>-YesCalled when a chosen tag is removed (pressed again in the list, or its × in the search box)
onCreateTag(data: Partial<OmittedTag>) => Promise<string>-YesCalled to create a tag from the search text. Returns the new id
onDeleteTag(tagId: string) => Promise<void>-YesCalled to delete a tag
onUpdateTag(tagId: string, data: Partial<OmittedTag>) => Promise<void>-YesCalled to change a tag's name or color

Trigger

PropTypeDefaultRequiredDescription
childrenReactNode-YesWhat opens the selector
asChildboolean-NoPuts the trigger behavior (role="button", tabIndex=0, Enter and Space) on the child instead of a wrapper

Data Attributes: data-state: "open" | "closed"

Content

PropTypeDefaultRequiredDescription
childrenReactNode-NoUsually Search and List
classNamestring-NoExtra CSS class
PropTypeDefaultRequiredDescription
placeholderstring'Search tags...'NoPlaceholder of the search input
maxLengthnumber'100'NoMaximum length of the search text

List

Renders the filtered tag list.

No props.

Specification

base

상태요소속성값
enabledcontentwidth296px토큰 아님 — no sizing token scale
enabledcontentmaxHeight400px토큰 아님 — no sizing token scale
enabledcontentpadding$size.space.200
enabledcontentgap$size.space.200
enabledcontentbackgroundColor$color.background.default.default
enabledcontentborderWidth$size.stroke.border
enabledcontentborderColor$color.border.default.default
enabledcontentborderRadius$size.radius.200
enabledsearchpadding$size.space.200
enabledsearchgap$size.space.200
enabledsearchborderRadius$size.radius.100
enabledsearchbackgroundColor$color.background.default.secondary
enabledsearchInputtypography$text.bodySmall
enabledsearchInputcolor$color.text.default.default
enableditemgap$size.space.100
enableditempaddingRight$size.space.200
enableditemborderRadius$size.radius.200
enabledselectButtonpaddingX$size.space.200
enabledselectButtonpaddingY$size.space.100
enabledselectButtongap$size.space.200
enabledselectButtonborderRadius$size.radius.200
enablededitButtonopacity0토큰 아님 — opacity keeps it reachable with Tab while hidden
hoveritembackgroundColor$color.background.default.defaultHover
hovereditButtonopacity1토큰 아님 — show
selectedcheckcolor$color.icon.default.default
focussearchstrokeWidth$size.stroke.focus
focussearchstrokeColor$color.border.brand.default
focuseditButtonopacity1토큰 아님 — show

Accessibility

Keyboard Interactions

KeyAction
TabMoves 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: ul labelled "Tags". Each row is a toggle button with aria-pressed; selected rows also show a check icon
  • Edit button: named Edit <tag name>, with aria-expanded while the editor is open. It is hidden with opacity (not display) until the row is hovered or focused, so Tab still 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
}