Combobox
An editable combobox: a text input with a filterable listbox of Options (APG combobox with list autocomplete). Typing filters the options; ArrowDown/ArrowUp move the highlight (aria-activedescendant), Enter selects, Escape closes. Without freeform the text is only a filter: its first match becomes active while typing, and the input shows the selected option's label again when the listbox closes. With freeform the text itself is the value. Text that matches no option shows "No matches" (labels.noMatches), announced through a status region. filter replaces the match (it may keep options that do not contain the text, for a server-side search or a "Create …" entry), and query/defaultQuery/onQueryChange control the typed text (not with freeform), which resets to '' on a commit, a close, a blur, Escape, the clear button and a form reset. The expand button at the end of the input (a chevron, see expandIcon) opens and closes the list without taking focus from the input and is not a tab stop; clearable adds a clear button, a tab stop after the input. Both sit with the input in a wrapper <div> inside the root.
multiselect turns the value into an array (Fluent's selectedOptions): options draw a checkbox; Enter and a click toggle an option and keep the list open (Tab, Escape and Alt+ArrowUp close without committing), and every toggle the user makes is announced (labels.added/labels.removed, never for a controlled change, a clear or a form reset). While no text is typed the input shows the selected labels in selection order (labels.selection, values without an option left out) instead of the placeholder. Focusing the input selects them, and so does their return to the focused input (a toggle, a close, a form reset), so typing, pasting or composing text replaces them with a query that filters the options; text inserted into them queries only what was inserted, an undo or a redo back to them shows them again, and a toggle, a close or a blur clears the query. Backspace and Delete only edit the text: the options, the clear button (which clears every value) and a form reset change the value. freeform is not available with multiselect, and a non-literal multiselect={flag} is a type error: render two elements, one for each mode.
**Data mode**: items passes the options as data instead of children. The open list renders an option per matching item (renderOption draws it, an Option with the item's label by default) and the closed list none; the keys, the filter and the input's text follow the data, and each option carries aria-posinset and aria-setsize among the shown options. A long list takes a virtualWindow (from useVirtualWindow({ itemSize })): the open list then renders only the options in view, plus an overscan, with spacers for the others, every option itemSize tall; the active option stays rendered, and opening scrolls it (else the first selected option) to the middle of the list.
The <input> receives ref, id, aria-label, aria-labelledby, aria-describedby, aria-invalid, aria-required, aria-errormessage, aria-details, tabIndex, autoFocus, onFocus/onBlur/onKeyDown/onKeyUp and the text input attributes autoComplete, autoCapitalize, autoCorrect, maxLength, inputMode, spellCheck and enterKeyHint. className, style, other aria-* attributes and the remaining props stay on the root <div> (slotProps.root.ref reaches it). Inside a Field the input is labelled and described by it. It shows the error look whenever it ends up aria-invalid (its own aria-invalid or a Field error). With name/required the value takes part in form submission (one hidden input per value with multiselect), validation and reset (a multiselect reset is compared by content, so restoring the same values reports nothing). The open listbox renders in a portal; while closed it stays in the DOM, hidden.
**Size and appearance**: size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the root <div>. The listbox keeps its size.
Sub-components: Combobox.Option, Combobox.OptionGroup. React Server Components import the flat names ComboboxOption / ComboboxOptionGroup (dotted access needs a client file).
Examples
Default
- Apple
- Banana
- Cherry
- Grape
- Orange
export const Default: Story = {
args: {
placeholder: 'Select a fruit...',
},
render: (args) => (
<Combobox {...args}>
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
<Option value="grape">Grape</Option>
<Option value="orange">Orange</Option>
</Combobox>
),
};Freeform
- Red
- Green
- Blue
export const Freeform: Story = {
args: {
'aria-label': 'Color',
placeholder: 'Type or select...',
freeform: true,
},
render: (args) => (
<Combobox {...args}>
<Option value="red">Red</Option>
<Option value="green">Green</Option>
<Option value="blue">Blue</Option>
</Combobox>
),
};Grouped
- Fruit
- Apple
- Banana
- Vegetables
- Carrot
- Pea (out of stock)
export const Grouped: Story = {
args: {
'aria-label': 'Produce',
placeholder: 'Search produce...',
},
render: (args) => (
<Combobox {...args}>
<OptionGroup label="Fruit">
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
</OptionGroup>
<OptionGroup label="Vegetables">
<Option value="carrot">Carrot</Option>
<Option value="pea" disabled>
Pea (out of stock)
</Option>
</OptionGroup>
</Combobox>
),
};Clearable
- Apple
- Banana
- Cherry
export const Clearable: Story = {
args: {
defaultValue: 'banana',
clearable: true,
placeholder: 'Select a fruit...',
},
render: (args) => (
<Combobox {...args}>
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>
),
};Multiselect
- Apple
- Banana
- Cherry
- Grape
- Orange
export const Multiselect: StoryObj<ComboboxProps<true>> = {
args: {
'aria-label': undefined,
multiselect: true,
clearable: true,
defaultValue: ['apple', 'cherry'],
placeholder: 'Select fruits...',
},
// `freeform` is not available with `multiselect`: hide the meta's control on this story.
argTypes: { freeform: { table: { disable: true } } },
// The spread alone leaves `multiselect` optional (StoryObj widens `args`), which satisfies
// neither call signature (D9): the literal attribute after it forces the multi-select one.
render: (args) => (
<Field label="Fruits">
<Combobox {...args} multiselect>
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
<Option value="grape">Grape</Option>
<Option value="orange">Orange</Option>
</Combobox>
</Field>
),
};Custom Filter
- Crème brûlée
- Éclair
- Mille-feuille
- Pain au chocolat
- Tarte Tatin
export const CustomFilter: Story = {
args: {
'aria-label': 'Dessert',
placeholder: 'Type the start of a dessert...',
},
render: (args) => (
<Combobox {...args} filter={startsWithIgnoringAccents}>
<Option value="creme-brulee">Crème brûlée</Option>
<Option value="eclair">Éclair</Option>
<Option value="mille-feuille">Mille-feuille</Option>
<Option value="pain-au-chocolat">Pain au chocolat</Option>
<Option value="tarte-tatin">Tarte Tatin</Option>
</Combobox>
),
};Async Search
- Argentina
- Australia
- Austria
- Belgium
- Brazil
- Canada
- Chile
- Denmark
export const AsyncSearch: Story = {
args: {
'aria-label': 'Country',
placeholder: 'Search countries...',
onQueryChange: fn(),
},
render: (args) => <AsyncSearchCombobox {...args} />,
};Without Expand Icon
- Apple
- Banana
- Cherry
export const WithoutExpandIcon: Story = {
args: {
expandIcon: false,
placeholder: 'Type to search...',
},
render: (args) => (
<Combobox {...args}>
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
<Option value="cherry">Cherry</Option>
</Combobox>
),
};Disabled
- Alpha
export const Disabled: Story = {
args: {
placeholder: 'Disabled',
disabled: true,
},
render: (args) => (
<Combobox {...args}>
<Option value="a">Alpha</Option>
</Combobox>
),
};Invalid
- Apple
- Banana
export const Invalid: Story = {
args: {
'aria-label': undefined,
placeholder: 'Select a fruit...',
},
render: (args) => (
<Field label="Fruit" error="Choose a fruit from the list." required>
<Combobox {...args}>
<Option value="apple">Apple</Option>
<Option value="banana">Banana</Option>
</Combobox>
</Field>
),
};Data Mode
export const DataMode: Story = {
args: {
'aria-label': 'Person',
placeholder: 'Search 500 people...',
defaultValue: 'person-321',
items: PEOPLE,
},
argTypes: {
items: { control: false },
renderOption: { control: false },
virtualWindow: { control: false },
},
};Ten Thousand Options
Mounted options: 0 of 10,000
export const TenThousandOptions: StoryObj<TenThousandOptionsArgs> = {
args: {
'aria-label': 'Person',
placeholder: 'Search 10,000 people...',
defaultValue: 'person-5000',
itemSize: 32,
style: { width: 300 },
},
argTypes: {
items: { control: false },
renderOption: { control: false },
virtualWindow: { control: false },
// Heights an option fits in; a smaller one would overlap the options.
itemSize: { control: 'select', options: [32, 40, 48] },
},
render: (args) => <TenThousandCombobox {...args} />,
};Ten Thousand Grouped Options
Mounted options: 0 of 10,000
export const TenThousandGroupedOptions: StoryObj<TenThousandOptionsArgs> = {
args: {
'aria-label': 'Person',
placeholder: 'Search 10,000 people...',
defaultValue: 'person-5000',
itemSize: 32,
style: { width: 300 },
},
argTypes: {
items: { control: false },
renderOption: { control: false },
renderGroup: { control: false },
virtualWindow: { control: false },
itemSize: { control: 'select', options: [32, 40, 48] },
},
render: (args) => <TenThousandGroupedCombobox {...args} />,
};Sizes And Appearances
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
- Apple
- Banana
export const SizesAndAppearances: Story = {
render: (args) => (
<SizeAppearanceGrid
render={(size, appearance) => (
<Combobox
{...args}
size={size}
appearance={appearance}
clearable
defaultValue="apple"
aria-label={`${size} ${appearance}`}
>
<Combobox.Option value="apple">Apple</Combobox.Option>
<Combobox.Option value="banana">Banana</Combobox.Option>
</Combobox>
)}
/>
),
};Motion
- Cat
- Dog
- Fish
- Cat
- Dog
- Fish
- Cat
- Dog
- Fish
export const Motion: Story = {
render: function MotionPopups(args) {
return (
<div className="flex flex-wrap gap-4">
{motionCases(fadeAndZoom).map(({ label, motion }) => (
<Combobox key={label} {...args} aria-label={label} motion={motion} placeholder={label}>
<Option value="cat">Cat</Option>
<Option value="dog">Dog</Option>
<Option value="fish">Fish</Option>
</Combobox>
))}
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
multiselect | boolean | No | false | Several options can be selected (Fluent's |
value | readonly string[] | string | No | Controlled selected value ( | |
defaultValue | readonly string[] | string | No | '' (`[]` with `multiselect`) | Initial selected value for uncontrolled usage. |
onValueChange | ((value: string[]) => void) | ((value: string) => void) | No | Called with the new value when it changes: an option is selected (toggled with | |
open | boolean | No | Controlled open state of the listbox. The list renders only in the browser: an open combobox is closed in the server HTML and opens once it has hydrated. | |
defaultOpen | boolean | No | false | Initial open state for uncontrolled usage. A combobox 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 combobox has hydrated. |
onOpenChange | (open: boolean) => void | No | Called when the listbox opens or closes. | |
placeholder | string | No | Placeholder text shown when no value is selected; with | |
disabled | boolean | No | false | Whether the combobox is disabled and non-interactive. |
size | 'small' | 'medium' | 'large' | No | Size of 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 combobox, 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: | |
freeform | boolean | No | false | Whether the typed text is itself the value. Without it, typing only filters the options (the first match becomes active, so Enter selects it) and the input shows the selected option's label again when the listbox closes or loses focus. With it, the input shows typed text as typed (also when it equals an option's value), a selected option's label, and a controlled |
filter | (option: ListboxItem, query: string) => boolean | No | a case-insensitive substring match on the option's `textValue`, else its `label` | Whether an option matches the typed text (the query, or with |
query | string | No | Controlled query: the text typed since the last commit, which filters the options. A non-empty query shows in the input (hidden while | |
defaultQuery | string | No | '' | Initial query for uncontrolled usage. A Combobox that starts disabled or read-only starts without it (as it starts closed). Not used with |
onQueryChange | (query: string) => void | No | Called with the new query when it changes: as the user types, and with | |
onActiveOptionChange | (value: string | null) => void | No | Called after the active (highlighted) option changes — opening, arrow keys, the pointer, a filter change that moves it — and with | |
disabledOptionsFocusable | boolean | No | false | Keeps disabled options in the arrow-key order (the first match highlighted while typing may then be a disabled one too); they still cannot be selected (Enter and a click do nothing and the list stays open). Unlike Fluent, which always keeps disabled options reachable, WaveUI skips them by default. |
name | string | No | Name of the value in form submissions (renders a hidden input; one per value with | |
form | string | No | Id of the form the value belongs to, when the Combobox is outside it. | |
required | boolean | No | A value 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 value cannot be changed: the input is read-only and the listbox neither opens (click, keyboard, a controlled | |
clearable | boolean | No | false | Shows a clear button while a value is selected (not while |
expandIcon | Slot<'span'> | No | The glyph of the expand button at the end of the input (default: a chevron). The button opens and closes the list without moving focus out of the input and is not a tab stop (Alt+ArrowDown opens the list from the keyboard). | |
labels | ComboboxLabels | No | The built-in texts (the "No matches" status, the names of the clear and expand buttons and, with | |
items | readonly ListboxItem[] | No | Data mode: the options as data, in list order ( | |
renderOption | (item: ListboxItem, state: ListboxOptionRenderState) => React.ReactNode | No | an `Option` with the item's `value`, `label` (also its text), `textValue` and `disabled` | Data mode: renders the option of an item, given its state ( |
renderGroup | (group: string, state: ListboxGroupRenderState) => React.ReactNode | No | the group's name, as text | Data mode: renders the header of a group of |
virtualWindow | VirtualWindow | No | Data mode: renders only the options in view of a long list, plus an overscan, and spacers ( The open popup's list is the window's scroller, so it needs no height of yours: it scrolls within its own maximum height (15rem, 240 pixels at the default root size, less where the viewport has no room). Every option is exactly The window counts the shown options: typing narrows it, as it narrows | |
onFocus | React.FocusEventHandler<HTMLInputElement> | No | Called when the | |
onBlur | React.FocusEventHandler<HTMLInputElement> | No | Called when the | |
onKeyDown | React.KeyboardEventHandler<HTMLInputElement> | No | Called on a key press in the | |
onKeyUp | React.KeyboardEventHandler<HTMLInputElement> | No | Called when a key is released in the | |
ref | React.Ref<HTMLInputElement> | No | Ref to the | |
slotProps | { root?: SlotPart<'div'>; input?: SlotPart<'input'>; clearButton?: SlotPart<'button'>; expandButton?: SlotPart<'button'>; listbox?: SlotPart<'ul'>; surface?: SlotPart<'div'>; emptyMessage?: SlotPart<'div'> } | No | Props for the elements the Combobox draws, by part, merged into each part's own (Fluent UI's |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
rootinputclearButtonexpandButtonlistboxsurfaceemptyMessageCombobox.OptionCombobox.OptionGroup
Stable class names
| Part | Class |
|---|---|
root | wave-combobox |
input | wave-combobox__input |
clearButton | wave-combobox__clear-button |
expandButton | wave-combobox__expand-button |
expandIcon | wave-combobox__expand-icon |
listbox | wave-combobox__listbox |
surface | wave-combobox__surface |
emptyMessage | wave-combobox__empty-message |
spacer | wave-combobox__spacer |