Repository navigation
Closed
Labels
Milestone
Description
Spec
Multi-select input with token chips and typeahead search. Composes XDSBaseTypeahead for search and XDSToken for selected items.
API
interface XDSTokenizerProps<T extends XDSSearchableItem> {
/** Accessible label (required) */
label: string;
/** Visually hide the label */
isLabelHidden?: boolean;
/** Helper text */
description?: string;
/** Required field */
isRequired?: boolean;
/** Optional field */
isOptional?: boolean;
/** Validation status */
status?: { type: "error" | "warning" | "success"; message?: string };
/** Label tooltip */
labelTooltip?: string;
/** Search source providing items */
searchSource: XDSSearchSource<T>;
/** Currently selected items */
value: T[];
/** Callback when selection changes */
onChange: (
items: T[],
change: { item: T; type: "add" | "remove" } | { type: "reorder" }
) => void;
/** Render function for dropdown items. Default: XDSTypeaheadItem */
renderItem?: (item: T) => ReactNode;
/** Render function for selected tokens. Default: XDSToken with label + onRemove */
renderToken?: (item: T) => ReactNode;
/** Max number of selections */
maxEntries?: number;
/** Placeholder text (shown when no tokens selected) */
placeholder?: string;
/** Show results on focus before typing */
hasEntriesOnFocus?: boolean;
/** Max dropdown items */
maxMenuItems?: number;
/** Text shown when no results found */
emptySearchResultsText?: string;
/** Whether the input is disabled */
isDisabled?: boolean;
/** Show clear button (clears all tokens) */
hasClear?: boolean;
/** Auto-focus on mount */
hasAutoFocus?: boolean;
/** Input size */
size?: "sm" | "md";
/** Query change callback */
onChangeQuery?: (query: string) => void;
/** StyleX overrides */
xstyle?: StyleXStyles;
/** Test ID */
"data-testid"?: string;
}Usage
// Basic
const [members, setMembers] = useState<UserItem[]>([]);
<XDSTokenizer
label="Team members"
searchSource={userSource}
value={members}
onChange={(items, change) => {
setMembers(items);
if (change.type === "add") console.log("Added:", change.item.label);
if (change.type === "remove") console.log("Removed:", change.item.label);
}}
placeholder="Search people..."
/>
// Custom rendering
<XDSTokenizer
label="Tags"
searchSource={tagSource}
value={tags}
onChange={(items) => setTags(items)}
renderItem={(item) => (
<XDSTypeaheadItem
item={item}
description={`${item.auxiliaryData.count} uses`}
/>
)}
renderToken={(item) => (
<XDSToken
label={item.label}
color={item.auxiliaryData.color}
icon={<TagIcon />}
/>
)}
maxEntries={5}
/>Behavior
- Tokens render inline before the text input
- Input grows/shrinks to fill remaining space
- Selecting an item adds a token and clears the query
- Backspace on empty input removes the last token
- Already-selected items are excluded from search results
- When
maxEntriesis reached, input is hidden
Accessibility
- Container:
role="group"witharia-label - Each token: focusable, remove button with
aria-label="Remove {label}" - Input:
role="combobox"(from XDSBaseTypeahead) - Keyboard: Tab between tokens, Backspace removes, arrow keys in dropdown
Design decisions
| Decision | Choice | Rationale |
|---|---|---|
| Rich onChange | (items, {item, type}) |
Consumers need to know what changed (add/remove/reorder) |
renderToken prop |
Function returning ReactNode | Customize token appearance (color, icon) per item |
renderItem prop |
Same as Typeahead | Shared dropdown rendering |
| Composes XDSBaseTypeahead | Shared search/dropdown logic | Avoid duplication with XDSTypeahead |
| Composes XDSToken | Shared token rendering | Consistent chip appearance |
v1 scope
Include: multi-select, tokens, search, renderItem, renderToken, maxEntries, clear, backspace removal
Defer: isReorderable (drag), truncationBehavior (collapse to one line), tokenizeQueryString, onPaste tokenization
Depends on
- Typeahead #80 (Typeahead — shared XDSBaseTypeahead, XDSSearchSource, XDSSearchableItem, XDSTypeaheadItem)
- XDSToken component (issue TBD or part of this)
Research
- Internal API analyzed: XDSTokenizer + internal component
External comparison
| Capability | XDSTokenizer | Mantine TagsInput | MUI Autocomplete (multiple) | Ant Select (mode="tags") |
React Aria TagGroup |
|---|---|---|---|---|---|
| Component model | Single <XDSTokenizer> composing XDSBaseTypeahead + XDSToken |
Single <TagsInput> built on Combobox |
<Autocomplete multiple> with renderTags |
<Select mode="tags"> |
Compound: TagGroup > TagList > Tag (display only — no input) |
| Value type | T[] — generic typed items with XDSSearchableItem |
string[] — string values only |
T[] — generic |
string[] — string values only |
Selection state via selectedKeys (display, not input) |
| Search / filtering | searchSource: XDSSearchSource<T> — async-capable, external |
Built-in filtering on data array |
filterOptions function on options array |
filterOption function on options / children |
N/A — TagGroup is display-only, not an input |
| Custom token rendering | renderToken — full control per token |
renderOption for dropdown; Pill styling via Styles API |
renderTags — full control over all chips |
tagRender — full control per tag |
children render function on Tag |
| Custom dropdown rendering | renderItem — per-item render function |
renderOption — per-option |
renderOption — per-option |
optionRender — per-option |
N/A |
| Free-form entry | Not in v1 (search-only) | ✅ Built-in — type and press Enter to create tags | freeSolo prop |
✅ Built-in — type to create | N/A |
| Max selections | maxEntries |
maxTags |
Not built-in (manual) | maxCount |
N/A |
| Backspace removal | ✅ Built-in | ✅ Built-in | ✅ Built-in | ✅ Built-in | N/A |
| Clear all | hasClear |
clearable |
disableClearable (inverted) |
allowClear |
N/A |
| onChange detail | (items, { item, type: "add" | "remove" }) — change metadata |
(value: string[]) — no detail |
(event, value, reason) — reason string |
(value, option) — no add/remove detail |
onRemove(keys) — remove only |
| Controlled query | onChangeQuery |
searchValue + onSearchChange |
inputValue + onInputChange |
searchValue + onSearch |
N/A |
| Reorder | Deferred (v2) | Not supported | Not supported | Not supported | Not supported |
| Disabled | isDisabled |
disabled |
disabled |
disabled |
isDisabled |
| Validation / status | status object (type + message) |
error (string) |
error (boolean) |
status ("error" / "warning") |
N/A |
| Field integration | label, description, isRequired, isOptional, labelTooltip |
label, description, required |
Via TextField props or renderInput |
Via Form.Item wrapper |
Label child component |
| Styling escape | xstyle (StyleX only) |
classNames / styles (Styles API) |
sx / className / slotProps |
className / style |
className / render props |
Key takeaways:
- React Aria's
TagGroupis display-only (no search input) — it's the tag list, not a tag input. XDSTokenizer covers both display and input. - Mantine TagsInput and Ant Select
mode="tags"use string-only values — XDSTokenizer's genericT extends XDSSearchableItemsupports rich typed objects. - XDSTokenizer's
onChangeprovides structured change metadata ({ item, type }) — most alternatives give only the new value array, requiring diffing. renderTokenfor per-token customization is closest to Ant'stagRender; MUI'srenderTagsgives control over the entire tag list at once.- Free-form entry (type-to-create) is deferred to v2 — this is built-in for Mantine and Ant.
Internal usage data
Based on internal codebase analysis of XDSTokenizer and internal component:
| Pattern | Observation |
|---|---|
| Primary use case | People pickers and entity selectors (teams, groups, tags) |
| Search source | Majority use async search sources (server-side filtering) |
| Custom rendering | renderToken used when tokens need color-coding or avatars; renderItem used for rich dropdown rows with descriptions |
| Max entries | Used in constrained contexts (e.g., "select up to 5 reviewers") |
| Backspace removal | Expected behavior — users rely on it heavily |
| Reorder | Requested but low usage (~deferred to v2) |
| Token colors | Colored tokens in tokenizers are rare — most use default styling |
| Composition with XDSToken | Internal tokenizer already composes the token component for selected items — XDSTokenizer continues this pattern |
Activity
cixzhang commentedon Mar 7, 2026
XDSTokenizer shipped in PR #299 and landed on main. Closing the spec tracking issue.