TagPicker
A multi-select combobox that shows the selected values as removable tags.
- **Two forms.** The array form, <TagPicker options={โฆ} />, is the parts with their defaults: TagPicker.Control (holding TagPicker.Group and TagPicker.Input) and TagPicker.List. The parts form replaces only the part you need: your own Tags in TagPicker.Group (an Avatar in each), rich TagPicker.Options in TagPicker.List, or TagPicker.Button, a select-only trigger, in place of the Input. Render TagPicker.Control and TagPicker.List directly inside TagPicker (a Fragment is fine); without a List the default list is added. options names the values in both forms (media and secondaryContent show in the default options, media in the default tags too); with a List that has children, its options are the options, and the options of selected values stay rendered (TagPicker hides them).
- **Keyboard.** Typing filters the options (filter, by default a case-insensitive match on textValue ?? label); the option whose label equals the typed text becomes active, else the first match. ArrowDown/ArrowUp move the highlight (aria-activedescendant), Enter adds the active option and keeps the list open (with nothing active, Enter is left to the surrounding form), Escape closes the list (and then clears the typed text). Backspace in the empty input, and Left (Right in RTL) with the caret at its start, focus the last tag; Delete, Backspace, Enter or Space on a remove button remove its tag and focus the next tag, else the input; a click on one focuses the input. Additions and removals are announced ("Cherry removed, 2 selected"), and so is "No matches" for text that matches no option.
- **Free tagging.** With allowCreate, text that matches no option label, no selected value (ignoring case) and no option value ends the list with a create option (Create "infra"); Enter on it or a click adds the text as a tag after onOptionCreate(text) and clears the text.
- **End buttons.** A chevron (expandIcon, false hides it) opens and closes the list without taking focus; clearable adds a clear button, a Tab stop after the input, which removes every tag. A press on the field's empty area toggles the list.
- **One line.** overflow="count" keeps the tags on one line while focus is outside the picker and its list is closed; the tags that do not fit give way to "+N".
- **Names.** The tags form a list named "Selected"; the trigger is described by a summary of the selected labels ("Selected: Apple, Banana"). These built-in texts are English; labels localizes them.
- **Routing.** The trigger that renders (TagPicker.Input or TagPicker.Button) receives ref, id, aria-label, aria-labelledby, aria-describedby, aria-invalid, aria-required, aria-errormessage, aria-details, tabIndex and autoFocus; the Input also onFocus/onBlur/onKeyDown/onKeyUp and the text input attributes autoComplete, autoCapitalize, autoCorrect, maxLength, inputMode, spellCheck and enterKeyHint (with the Button, pass handlers on it). ref follows the trigger: the built-in Input, your TagPicker.Input, or TagPicker.Button in its place. className, style, other aria-* attributes and the remaining props stay on the root <div> (slotProps.root.ref reaches it). Inside a Field the trigger is labelled and described by it; the field shows the error look whenever the trigger ends up aria-invalid. With name/required the values take part in form submission, validation and reset. Selected values without a matching option show their raw value.
- **Size and appearance**: size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium' (a Field or provider small gives 'medium' too, since TagPicker has no small); appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the root <div>, and the parts take neither. The tags are one Tag size smaller. The option list keeps its size.
- **Server rendering.** The open list renders only in the browser: an open list (defaultOpen, open) is closed in the server HTML and opens once the picker has hydrated; the tags of registered options show their labels in the server HTML.
Fluent's selectedOptions and onOptionSelect are value and onValueChange (plus onOptionCreate). TagPickerOption is both the type of an options entry and the flat name of TagPicker.Option.
Examples
Default
export const Default: Story = {
args: {
placeholder: 'Select fruits...',
},
};With Preselected
export const WithPreselected: Story = {
args: {
defaultValue: ['apple', 'cherry'],
placeholder: 'Select fruits...',
},
};Disabled
export const Disabled: Story = {
args: {
defaultValue: ['banana'],
disabled: true,
},
};Read Only
export const ReadOnly: Story = {
args: {
defaultValue: ['apple', 'cherry'],
readOnly: true,
},
};Custom Filter
export const CustomFilter: Story = {
args: {
'aria-label': 'Desserts',
options: [
{ value: 'creme-brulee', label: 'Crรจme brรปlรฉe' },
{ value: 'eclair', label: 'รclair' },
{ value: 'mille-feuille', label: 'Mille-feuille' },
{ value: 'pain-au-chocolat', label: 'Pain au chocolat' },
{ value: 'tarte-tatin', label: 'Tarte Tatin' },
],
placeholder: 'Type the start of a dessert...',
},
render: (args) => (
<TagPicker
{...args}
filter={(option: ListboxItem, query: string) => fold(option.label).startsWith(fold(query))}
/>
),
};Async Search
export const AsyncSearch: Story = {
args: {
'aria-label': 'Countries',
placeholder: 'Search countries...',
onQueryChange: fn(),
},
render: (args) => <AsyncSearchTagPicker {...args} />,
};Invalid
export const Invalid: Story = {
args: {
'aria-label': undefined,
placeholder: 'Select fruits...',
},
render: (args) => (
<Field label="Fruits" error="Pick at least one fruit." required>
<TagPicker {...args} />
</Field>
),
};Sizes And Appearances
export const SizesAndAppearances: Story = {
render: (args) => (
<div className="grid gap-4">
{(['outline', 'underline', 'filled-darker', 'filled-lighter'] as const).map((appearance) => (
<div
key={appearance}
className={
appearance === 'filled-lighter'
? 'grid grid-cols-3 items-start gap-3 rounded bg-wave-secondary p-3'
: 'grid grid-cols-3 items-start gap-3 p-3'
}
>
{(['medium', 'large', 'extra-large'] as const).map((size) => (
<TagPicker
{...args}
key={size}
size={size}
appearance={appearance}
options={FRUIT}
defaultValue={['apple']}
clearable
aria-label={`${size} ${appearance}`}
>
<TagPicker.Control>
<TagPicker.Group />
<TagPicker.Input />
</TagPicker.Control>
<TagPicker.List />
</TagPicker>
))}
</div>
))}
</div>
),
};People Picker
- Katri AthokasDesigner
- Elvia AtkinsEngineer
- Cameron EvansProduct manager
- Mona KaneResearcher
- Wanda HowardEngineering manager
export const PeoplePicker: Story = {
args: { 'aria-label': 'People', placeholder: 'Add people...' },
render: (args) => <PeoplePickerExample {...args} />,
};Composed Parts
- Apple
- Banana
- Cherry
- Date
- Elderberry
- Fig
- Grape
export const ComposedParts: Story = {
render: (args) => <ComposedPartsExample {...args} />,
};Option Groups
- Fruit
- Apple
- Pear
- Vegetables
- Carrot
- Leek
export const OptionGroups: Story = {
args: { 'aria-label': 'Produce', defaultValue: ['apple'] },
render: (args) => (
<TagPicker {...args} options={undefined}>
<TagPicker.Control />
<TagPicker.List>
<TagPicker.OptionGroup label="Fruit">
<TagPicker.Option value="apple">Apple</TagPicker.Option>
<TagPicker.Option value="pear">Pear</TagPicker.Option>
</TagPicker.OptionGroup>
<TagPicker.OptionGroup label="Vegetables">
<TagPicker.Option value="carrot">Carrot</TagPicker.Option>
<TagPicker.Option value="leek">Leek</TagPicker.Option>
</TagPicker.OptionGroup>
</TagPicker.List>
</TagPicker>
),
};Button Trigger
export const ButtonTrigger: Story = {
args: { 'aria-label': 'Fruits', placeholder: 'Choose fruits' },
render: (args) => (
<TagPicker {...args}>
<TagPicker.Control>
<TagPicker.Group />
<TagPicker.Button />
</TagPicker.Control>
<TagPicker.List />
</TagPicker>
),
};Free Tagging
export const FreeTagging: Story = {
args: { 'aria-label': 'Topics', placeholder: 'Add topics...', onOptionCreate: fn() },
render: (args) => <FreeTaggingExample {...args} />,
};Free Tagging With Async Search
export const FreeTaggingWithAsyncSearch: Story = {
args: {
'aria-label': 'Destinations',
placeholder: 'Search or add...',
onQueryChange: fn(),
onOptionCreate: fn(),
},
render: (args) => <FreeTaggingAsyncExample {...args} />,
};Clearable
export const Clearable: Story = {
args: { clearable: true, defaultValue: ['apple', 'cherry', 'fig'] },
};Single Line
export const SingleLine: Story = {
args: {
overflow: 'count',
defaultValue: ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig'],
},
render: (args) => (
<div className="w-72">
<TagPicker {...args} />
</div>
),
};Expand Icon
export const ExpandIcon: Story = {
render: (args) => (
<div className="grid gap-3">
<TagPicker {...args} aria-label="Fruits with a custom glyph" expandIcon={<span>โพ</span>} />
<TagPicker {...args} aria-label="Fruits without an expand button" expandIcon={false} />
</div>
),
};Localized Labels
export const LocalizedLabels: Story = {
args: {
'aria-label': 'Frukt',
placeholder: 'Velg frukt...',
defaultValue: ['apple', 'banana', 'cherry', 'date'],
clearable: true,
allowCreate: true,
overflow: 'count',
labels: {
remove: (label) => `Fjern ${label}`,
selected: 'Valgt',
summary: (labels) => `Valgt: ${labels.join(', ')}`,
added: (label, count) => `${label} lagt til, ${count} valgt`,
removed: (label, count) => `${label} fjernet, ${count} valgt`,
noMatches: 'Ingen treff',
create: (text) => `Opprett ยซ${text}ยป`,
clear: 'Fjern alle',
expand: 'Vis alternativer',
overflowCount: (count) => `+${count}`,
},
},
render: (args) => (
<div className="w-72">
<TagPicker {...args} />
</div>
),
};Motion
export const Motion: Story = {
render: function MotionPopups(args) {
return (
<div className="flex flex-wrap gap-4">
{motionCases(fadeAndZoom).map(({ label, motion }) => (
<TagPicker
key={label}
{...args}
aria-label={label}
motion={motion}
options={fruitOptions}
placeholder={label}
/>
))}
</div>
);
},
};No Popover
export const NoPopover: Story = {
args: {
'aria-label': 'Topics',
placeholder: 'Type a topic and press Enter',
noPopover: true,
allowCreate: true,
onOptionCreate: fn(),
},
};Secondary Action
export const SecondaryAction: Story = {
render: (args) => <SecondaryActionExample {...args} />,
};Disabled Options
export const DisabledOptions: Story = {
args: {
options: fruitOptions.map((option) => ({ ...option, disabled: option.value === 'cherry' })),
},
};Windowed
export const Windowed: Story = {
render: (args) => <WindowedExample {...args} />,
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
options | readonly TagPickerOption[] | No | The options, the array form ( | |
children | React.ReactNode | No | The parts: | |
value | readonly string[] | No | Controlled array of selected option values ( | |
defaultValue | readonly string[] | No | [] | Initial selected values for uncontrolled usage; a form reset restores them. |
onValueChange | (value: string[]) => void | No | Called with the new selection when it changes: a tag is added (an option, or a created tag) or removed, or a form reset restores different tags. Fluent's | |
open | boolean | No | Controlled open state of the option list. The list renders only in the browser: an open picker is closed in the server HTML and opens once it has hydrated. | |
defaultOpen | boolean | No | false | Initial open state for uncontrolled usage. A picker that starts disabled or read-only starts closed. The list renders only in the browser: it is closed in the server HTML and opens once the picker has hydrated. |
onOpenChange | (open: boolean) => void | No | Called when the option list opens or closes. | |
placeholder | string | No | 'Select...' | Shown by TagPicker.Input or TagPicker.Button while no tag is selected; the part's own |
filter | (option: ListboxItem, query: string) => boolean | No | a case-insensitive substring match on the option's `textValue ?? label` | Whether an option matches the typed text (the query). Called with every listed option, also the options of |
query | string | No | Controlled query: the text typed since the last tag was added, which filters the options and shows in the input (hidden while | |
defaultQuery | string | No | '' | Initial query for uncontrolled usage. A TagPicker that starts disabled or read-only starts without it (as it starts closed). Not used with TagPicker.Button. |
onQueryChange | (query: string) => void | No | Called with the new query when it changes: as the user types, and with | |
virtualWindow | VirtualWindow | No | Renders only the options in view of a long list of | |
disabled | boolean | No | false | Whether the tag picker is disabled: nothing can be added or removed, the remove buttons leave the tab order, and the expand and clear buttons are disabled. The field dims once. |
size | 'medium' | 'large' | 'extra-large' | No | Size of the tags and the field: | |
positioning | PopupPositioningOptions | No | `{ matchReferenceWidth: true, fitViewport: true }` | Advanced positioning of the popup (Fluent's |
motion | MotionSlot | null | No | the fade and slide above | The popup surface's motion. By default it fades in and slides 4px away from the field, on the side it opened on, over 200 ms with a decelerating curve, and fades out and slides back over 100 ms with an accelerating curve (the list stays in the surface while it exits); under reduced motion it appears and disappears at once. The list does not fade out when its options changed as it closed (a filter reset by the selection), nor does the "No matches" row. |
appearance | 'outline' | 'underline' | 'filled-darker' | 'filled-lighter' | No | Look of the field: | |
name | string | No | Name of the values in form submissions (one hidden input per value). | |
form | string | No | Id of the form the values belong to, when the TagPicker is outside it. | |
required | boolean | No | At least one tag is required to submit the form (native constraint validation). Like a native readonly input, a | |
autoComplete | string | No | 'off' | The |
maxLength | number | No | The maximum length of the typed text ( | |
readOnly | boolean | No | The selection cannot be changed: the trigger is read-only, the tags have no remove buttons, the expand button is disabled and the clear button hidden, and the option list neither opens (click, keyboard, a controlled | |
allowCreate | boolean | No | false | Lets the user add a tag of their own text: while the trimmed text matches no option label and no selected value (ignoring case) and no option value, the list ends with a create option ( |
onOptionCreate | (text: string, details?: TagPickerCreateDetails) => void | No | Called with the trimmed text when the user creates a tag, before | |
noPopover | boolean | No | false | Leaves the list out: the picker is a text field that adds tags of its own. There is no popup, no |
secondaryAction | Slot<'span'> | No | An action after the trigger, before the end buttons (a clear-all or an "Add all" button): rendered in a | |
clearable | boolean | No | false | Shows a clear button at the end of the field while a tag is selected (not while |
expandIcon | Slot<'span'> | No | The glyph of the expand button at the end of the field (default: a chevron). The button opens and closes the list, keeps focus on the trigger and is not a Tab stop. | |
overflow | 'wrap' | 'count' | No | 'wrap' |
|
labels | TagPickerLabels | No | Names of the remove buttons and the tag list, the summary that describes the trigger, the announcements, the "No matches" text, the create option, the clear and expand buttons and the "+N" count, for localization. Unset members keep their English defaults. | |
onFocus | React.FocusEventHandler<HTMLInputElement> | No | Called when TagPicker.Input's | |
onBlur | React.FocusEventHandler<HTMLInputElement> | No | Called when TagPicker.Input's | |
onKeyDown | React.KeyboardEventHandler<HTMLInputElement> | No | Called on a key press in TagPicker.Input's | |
onKeyUp | React.KeyboardEventHandler<HTMLInputElement> | No | Called when a key is released in TagPicker.Input's | |
ref | React.Ref<HTMLInputElement | HTMLButtonElement> | No | Ref to the trigger that renders, the focusable control (Fluent UI's | |
slotProps | { root?: SlotPart<'div'>; tag?: SlotPart<'span'>; removeButton?: SlotPart<'button'>; expandButton?: SlotPart<'button'>; clearButton?: SlotPart<'button'>; option?: SlotPart<'li'>; createOption?: SlotPart<'li'>; overflowCount?: SlotPart<'span'>; surface?: SlotPart<'div'>; emptyMessage?: SlotPart<'div'> } | No | Props for the elements TagPicker generates in its parts, by part, merged into each part's own (Fluent UI's TagPicker parts take their own props, as |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
roottagremoveButtonexpandButtonclearButtonoptioncreateOptionoverflowCountsurfaceemptyMessageTagPicker.ControlTagPicker.GroupTagPicker.InputTagPicker.ButtonTagPicker.ListTagPicker.OptionTagPicker.OptionGroup
Stable class names
| Part | Class |
|---|---|
root | wave-tag-picker |
tag | wave-tag-picker__tag |
removeButton | wave-tag-picker__remove-button |
input | wave-tag-picker__input |
expandButton | wave-tag-picker__expand-button |
expandIcon | wave-tag-picker__expand-icon |
clearButton | wave-tag-picker__clear-button |
listbox | wave-tag-picker__listbox |
option | wave-tag-picker__option |
createOption | wave-tag-picker__create-option |
overflowCount | wave-tag-picker__overflow-count |
surface | wave-tag-picker__surface |
emptyMessage | wave-tag-picker__empty-message |
spacer | wave-tag-picker__spacer |
secondaryAction | wave-tag-picker__secondary-action |