Components

Combobox

An input combined with a list of predefined items to select.

Usage guidelines#

  • Combobox is a filterable Select: Use Combobox when the input is restricted to a set of predefined selectable items, similar to Select but whose items are filterable using an input. Prefer using Combobox over Select when the number of items is sufficiently large to warrant filtering.
  • Avoid for simple search widgets: Combobox does not allow free-form text input. For search widgets, consider using Autocomplete instead.
  • Avoid when not rendering an input: Use Select instead of Combobox if no input is being rendered, which includes accessibility features specific to a listbox without an input.
  • Form controls must have an accessible name: If <Combobox.Input> is the form control, label it with a native <label> or <Field.Label>, or provide an aria-label when no visible label is rendered. <Combobox.Label> labels <Combobox.Trigger> and is intended for the input-inside-popup pattern, where the trigger is the form control.
  • Closing animations: The popup stays rendered until its closing animation finishes. Style the [data-ending-style] state to animate it out.

Anatomy#

Import the components and place them together:

Anatomytsx
import { Combobox } from '@egoist/solid-base/combobox';

<Combobox.Root>
  <Combobox.Label />

  <Combobox.InputGroup>
    <Combobox.Input />
    <Combobox.Trigger />
    <Combobox.Icon />
    <Combobox.Clear />
    <Combobox.Value />

    <Combobox.Chips>
      <Combobox.Chip>
        <Combobox.ChipRemove />
      </Combobox.Chip>
    </Combobox.Chips>
  </Combobox.InputGroup>

  <Combobox.Portal>
    <Combobox.Backdrop />
    <Combobox.Positioner>
      <Combobox.Popup>
        <Combobox.Arrow />

        <Combobox.Status />
        <Combobox.Empty />

        <Combobox.List>
          <Combobox.Row>
            <Combobox.Item>
              <Combobox.ItemIndicator />
            </Combobox.Item>
          </Combobox.Row>

          <Combobox.Separator />

          <Combobox.Group>
            <Combobox.GroupLabel />
          </Combobox.Group>

          <Combobox.Collection />
        </Combobox.List>
      </Combobox.Popup>
    </Combobox.Positioner>
  </Combobox.Portal>
</Combobox.Root>;

Item values#

Each <Combobox.Item> takes a value prop identifying it. Pass the item being rendered:

Using item objects as valuestsx
<Combobox.List>
  {(item: Fruit) => <Combobox.Item value={item}>{item.label}</Combobox.Item>}
</Combobox.List>

That item is what value, defaultValue, and onValueChange receive. To store IDs instead, see Value selection with IDs.

Examples#

Typed wrapper component#

The following example shows a typed wrapper around the Combobox component with correct type inference and type safety:

Specifying generic type parameterstsx
import type { JSX } from '@solidjs/web';
import { Combobox } from '@egoist/solid-base/combobox';

export function MyCombobox<Value, Multiple extends boolean | undefined = false, Item = Value>(
  props: Combobox.Root.Props<Value, Multiple, Item>,
): JSX.Element {
  return <Combobox.Root {...props}>{/* ... */}</Combobox.Root>;
}

The third Item type parameter is what lets the wrapper accept a Combobox.createItems() collection, whose rendered item type differs from its selection value. Omit it and a collection infers Value as the source item type, surfacing an error on defaultValue rather than on items.

Value selection with IDs#

When your app stores IDs rather than item objects, use Combobox.createItems with getValue and getLabel to derive each item's selection value and display label.

With static data, create the collection at module scope. The accessor parameters are inferred from users. Pass the derived ID to the value prop of <Combobox.Item>, not the item being rendered:

Using item IDs as valuestsx
const items = Combobox.createItems(users, {
  getValue: (user) => user.id,
  getLabel: (user) => user.name,
});

<Combobox.Root items={items}>
  <Combobox.List>
    {(user: User) => <Combobox.Item value={user.id}>{user.name}</Combobox.Item>}
  </Combobox.List>
</Combobox.Root>;

Selection props and events use the derived IDs, while list rendering continues to receive the original items. The derived label is also used for filtering and typeahead.

When the data is loaded or replaced at runtime, derive the collection with createMemo so that it is rebuilt only when the data changes:

Creating a collection from dynamic datatsx
const items = createMemo(() =>
  Combobox.createItems(users(), {
    getValue: (user) => user.id,
    getLabel: (user) => user.name,
  }),
);

<Combobox.Root items={items()}>{/* ... */}</Combobox.Root>;

As a rule of thumb, use primitive items for simple lists, object values when the selected record is useful application state, and createItems() when selection should use a stable primitive ID while rendering and filtering still use object records.

Stable IDs preserve item matching when an async data library replaces row objects during a refetch. With object values, use isItemEqualToValue to compare their IDs instead.

When results are filtered externally (for example, by a server-side search), items represents records known to the app, while filteredItems represents the current result window displayed in the popup. Pass source items rather than derived values to filteredItems, preserving the flat or grouped structure of items:

Displaying a window of async resultstsx
const items = createMemo(() =>
  Combobox.createItems(knownUsers(), {
    getValue: (user) => user.id,
    getLabel: (user) => user.name,
  }),
);

<Combobox.Root
  items={items()}
  filteredItems={searchResults()}
  value={selectedUserId()}
  onValueChange={(id) => setSelectedUserId(id)}
/>;

Include the selected user's record in knownUsers so its label remains available when it is outside searchResults. Alternatively, provide itemToStringLabel when the label can be derived from the selected value alone.

Multiple select#

The combobox can allow multiple selections by adding the multiple prop to <Combobox.Root>. Selection chips are rendered with <Combobox.Chip> inside the input that can be removed.

In order for screen readers to announce how to reach and remove the chips, add aria-description to <Combobox.Chip> and <Combobox.Input>, alongside the aria-label on <Combobox.Chips> and <Combobox.ChipRemove>. The library does not ship these strings. Translate them together with the rest of your interface.

Visible chips can be limited by slicing the selected values:

Limiting visible chipstsx
const CHIP_LIMIT = 3;

const [value, setValue] = createSignal<string[]>([]);
const visibleValue = () => value().slice(0, CHIP_LIMIT);
const hiddenCount = () => value().length - visibleValue().length;

<Combobox.Root items={items} multiple value={value()} onValueChange={(next) => setValue(next)}>
  <Combobox.Chips>
    <For each={visibleValue()}>
      {(item) => (
        <Combobox.Chip aria-description="Press Backspace or Delete to remove">
          {item}
          <Combobox.ChipRemove aria-label={`Remove ${item}`} />
        </Combobox.Chip>
      )}
    </For>
    <Show when={hiddenCount() > 0}>
      <span>{`+${hiddenCount()} more`}</span>
    </Show>
    <Combobox.Input
      aria-description={
        value().length > 0
          ? `${value().length} selected. From the start of the input, press Left Arrow to focus the selected items`
          : undefined
      }
    />
  </Combobox.Chips>
  {/* ... */}
</Combobox.Root>;

Keeping the filter after selection

In multiple mode, selecting an item clears the typed filter and closes the popup when the input is rendered outside it. To let users pick several results from one query, cancel the relevant change request.

Which request to cancel depends on the input's placement. When the input is outside the popup, cancel the item-press close request in onOpenChange. When it is inside, cancel the clear request in onInputValueChange, marked with eventDetails.isItemPress.

Input outside the popuptsx
<Combobox.Root
  multiple
  onOpenChange={(open, eventDetails) => {
    if (!open && eventDetails.reason === 'item-press') {
      eventDetails.cancel();
    }
  }}
>
  {/* ... */}
</Combobox.Root>
Input inside the popuptsx
<Combobox.Root
  multiple
  onInputValueChange={(value, eventDetails) => {
    if (eventDetails.isItemPress) {
      eventDetails.cancel();
    }
  }}
>
  {/* ... */}
</Combobox.Root>

The typed filter still resets once the popup closes.

Input inside popup#

<Combobox.Input> can be rendered inside <Combobox.Popup> to create a searchable select popup.

Country

Use <Combobox.Label> to provide a visible label for the combobox trigger in this pattern:

Using Combobox.Label to label a comboboxtsx
<Combobox.Root>
  <Combobox.Label>Favorite fruit</Combobox.Label>
  {/* ... */}
</Combobox.Root>

<Combobox.Label> renders a <div>, so clicking it focuses the combobox trigger without opening the popup.

Grouped#

Organize related options with <Combobox.Group> and <Combobox.GroupLabel> to add section headings inside the popup.

Groups are represented by an array of objects with an items property, which itself is an array of individual items for each group. An extra property, such as value, can be provided for the heading text when rendering the group label.

Exampletsx
interface ProduceGroupItem {
  value: string;
  items: string[];
}

const groups: ProduceGroupItem[] = [
  {
    value: 'Fruits',
    items: ['Apple', 'Banana', 'Orange'],
  },
  {
    value: 'Vegetables',
    items: ['Carrot', 'Lettuce', 'Spinach'],
  },
];

Pass each group's items to <Combobox.Group> and render them with <Combobox.Collection>, which receives only the group's filtered items:

Async search (single)#

Load items from a remote source by fetching on input changes. Keep the selected item in the items list so it remains available while new results stream in. This pattern avoids needing to load items upfront.

Async search (multiple)#

Load items from a remote source by fetching on input changes while supporting multiple selections. Selected items remain available in the list while new matches stream in. This pattern avoids needing to load items upfront.

Virtualized#

Efficiently handle large datasets by rendering only the visible items. Set virtualized on <Combobox.Root>, read the filtered items with Combobox.useFilteredItems(), and give each rendered <Combobox.Item> its index in the filtered list. Use onItemHighlighted to scroll a highlighted item into view when it is outside the rendered window.

Rendering cost without virtualization

In React, datasets up to roughly 1,000 items call for wrapping each item in React.memo. That isn't needed in Solid: the list is rendered with a keyed <For>, so typing a query only inserts and removes the items whose match changed, and the remaining items are never re-rendered. Virtualization is still worth it for very large datasets, where the cost of mounting every item when the popup opens dominates.

API reference#

<Combobox.Root>

Groups all parts of the combobox. Doesn't render its own HTML element.

PropTypeDefault
idstring—

The id of the component.

disabledbooleanfalse

Whether the component should ignore user interaction.

formstring—

Identifies the form that owns the internal input. Useful when the combobox is rendered outside the form.

namestring—

Identifies the field when a form is submitted.

readOnlybooleanfalse

Whether the user should be unable to choose a different option from the popup.

requiredbooleanfalse

Whether the user must choose a value before submitting a form.

filter| null | ((item: Item, query: string, itemToString?: (item: Item) => string) => boolean)—

Filter function used to match items vs input query. Receives the source item, which is the derived value's item when items is a createItems() collection, and the item itself otherwise.

itemsreadonly any[] | readonly Group<any>[] | ComboboxItemCollection<Item, ItemValue>—

The items to be displayed in the list. Can be a flat array of items, an array of groups with items, or a collection created by the createItems() function, which derives each item's selection value and label. Nullish entries are not supported: remove them from the data before passing it.

inputValuestring | number | readonly string[]—

The input value of the combobox. Use when controlled.

defaultInputValuestring | number | readonly string[]—

The uncontrolled input value when initially rendered.

To render a controlled input, use the inputValue prop instead.

inlinebooleanfalse

Whether the list is rendered inline without using the component's own popup.

Specify open unconditionally in conjunction with this prop so the list is considered visible: <Combobox.Root inline open>

openOnInputClickbooleantrue

Whether the popup opens when clicking the input.

filteredItemsreadonly Item[] | readonly Group<Item>[]—

Filtered items to display in the list. When provided, the list uses these items instead of filtering the items prop internally. When items is also provided, this array must preserve its flat or grouped structure. With a createItems() collection, pass source items rather than derived values. Nullish entries are not supported, as in items. Use when you want to control filtering logic externally with the useFilter() hook.

defaultOpenbooleanfalse

Whether the popup is initially open.

To render a controlled popup, use the open prop instead.

openboolean—

Whether the popup is currently open. Use when controlled.

onOpenChangeComplete((open: boolean) => void)—

Event handler called after any animations complete when the popup is opened or closed.

loopFocusbooleantrue

Whether to loop keyboard focus back to the input when the end of the list is reached while using the arrow keys. The first item can then be reached by pressing <kbd>ArrowDown</kbd> again from the input, or the last item can be reached by pressing <kbd>ArrowUp</kbd> from the input. The input is always included in the focus loop per ARIA Authoring Practices. When disabled, focus does not move when on the last element and the user presses <kbd>ArrowDown</kbd>, or when on the first element and the user presses <kbd>ArrowUp</kbd>.

inputRefRefProp<HTMLInputElement>—

A ref to the hidden input element.

gridbooleanfalse

Whether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows.

virtualizedbooleanfalse

Whether the items are being externally virtualized.

modalbooleanfalse

Determines if the popup enters a modal state when open. - true: user interaction is limited to the popup: document page scroll is locked and pointer interactions on outside elements are disabled. - false: user interaction with the rest of the document is allowed.

limitnumber-1

The maximum number of items to display in the list.

localeIntl.LocalesArgument—

The locale to use for string comparison. Defaults to the user's runtime locale.

multipleMultiplefalse

Whether multiple items can be selected.

autoCompletestring—

Provides a hint to the browser for autofill.

autoHighlightbooleanfalse

Whether the first matching item is highlighted automatically while filtering.

highlightItemOnHoverbooleantrue

Whether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.

itemToStringLabel((itemValue: Value) => string)—

When the item values are objects (<Combobox.Item value={object}>), this function converts the object value to a string representation for display in the input. If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop. With a createItems() collection, this receives the derived value, and the collection's getLabel takes precedence for values it can resolve.

itemToStringValue((itemValue: Value) => string)—

When the item values are objects (<Combobox.Item value={object}>), this function converts the object value to a string representation for form submission. If the shape of the object is { value, label }, the value will be used automatically without needing to specify this prop. With a createItems() collection, this receives the derived value.

isItemEqualToValue((itemValue: Value, value: Value) => boolean)—

Custom comparison logic used to determine if a combobox item value matches the current selected value. Useful when item values are objects without matching referentially. With a createItems() collection, both arguments are derived values. Defaults to Object.is comparison.

defaultValueComboboxInputValue<Value, Multiple> | null—

The uncontrolled selected value of the combobox when it's initially rendered.

To render a controlled combobox, use the value prop instead.

actionsRefActionsRef<ComboboxRoot.Actions>—

A ref to imperative actions: a ref object ({ current: null }) or a callback receiving them. - unmount: Ends the closing phase of the combobox after an externally controlled closing animation finishes. Call preventUnmountOnClose() in onOpenChange first, otherwise the combobox completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal. - close: Closes the combobox imperatively when called.

onOpenChange((open: boolean, eventDetails: ComboboxRoot.OpenChangeEventDetails) => void)—

Event handler called when the popup is opened or closed.

onInputValueChange((inputValue: string, eventDetails: ComboboxRoot.ChangeEventDetails) => void)—

Event handler called when the input value changes.

onItemHighlighted| (( highlightedValue: Value, eventDetails: ComboboxRoot.HighlightEventDetails, ) => void)—

Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item value (or undefined if no item is highlighted) and event details with a reason property describing why the highlight changed. The reason can be: - 'keyboard': the highlight changed due to keyboard navigation. - 'pointer': the highlight changed due to pointer hovering. The event may be a MouseEvent rather than a PointerEvent. - 'none': the highlight changed for another reason, such as typing, autoHighlight, the item list changing, or the popup opening or closing.

valueComboboxInputValue<Value, Multiple> | null—

The selected value of the combobox. Use when controlled.

onValueChange| (( value: ComboboxOutputValue<Value, Multiple> | (Multiple extends true ? never : null), eventDetails: ComboboxRoot.ChangeEventDetails, ) => void)—

Event handler called when the selected value of the combobox changes.

<Combobox.Trigger>

A button that opens the popup. Renders a <button> element.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

nativeButtonbooleantrue

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the component is disabled.

data-readonly

Present when the component is readonly.

data-popup-side

Indicates which side the corresponding popup is positioned relative to its anchor.

data-required

Present when the component is required.

data-valid

Present when the component is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the component is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the component has been touched (when wrapped in Field.Root).

data-dirty

Present when the component's value has changed (when wrapped in Field.Root).

data-filled

Present when the component has a value (when wrapped in Field.Root).

data-focused

Present when the trigger is focused (when wrapped in Field.Root).

data-list-empty

Present when the corresponding items list is empty.

data-placeholder

Present when the combobox doesn't have a value.

<Combobox.Label>

An accessible label that is automatically associated with the combobox trigger. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Value>

The current value of the combobox. Doesn't render its own HTML element.

PropTypeDefault
placeholderJSX.Element—

The placeholder value to display when no value is selected. This is overridden by children if specified, or by a null item's label in items.

<Combobox.Input>

A text input to search for items in the list. Renders an <input> element.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the component is disabled.

data-readonly

Present when the component is readonly.

data-popup-side

Indicates which side the corresponding popup is positioned relative to its anchor.

data-required

Present when the component is required.

data-valid

Present when the component is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the component is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the component has been touched (when wrapped in Field.Root).

data-dirty

Present when the component's value has changed (when wrapped in Field.Root).

data-filled

Present when the component has a value (when wrapped in Field.Root).

data-focused

Present when the input is focused (when wrapped in Field.Root).

data-list-empty

Present when the corresponding items list is empty.

<Combobox.InputGroup>

A wrapper for the input and its associated controls. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-popup-open

Present when the corresponding popup is open.

data-pressed

Present when the input group is pressed.

data-disabled

Present when the component is disabled.

data-readonly

Present when the component is readonly.

data-popup-side

Indicates which side the corresponding popup is positioned relative to its anchor.

data-valid

Present when the component is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the component is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the component has been touched (when wrapped in Field.Root).

data-dirty

Present when the component's value has changed (when wrapped in Field.Root).

data-filled

Present when the component has a value (when wrapped in Field.Root).

data-focused

Present when the component is focused (when wrapped in Field.Root).

data-list-empty

Present when the corresponding items list is empty.

data-placeholder

Present when the combobox doesn't have a value.

<Combobox.List>

A list container for the items. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Status>

Displays a status message whose content changes are announced politely to screen readers. Useful for conveying the status of an asynchronously loaded list. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Portal>

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

PropTypeDefault
keepMountedbooleanfalse

Whether to keep the portal mounted in the DOM while the popup is hidden.

containerPortalContainer—

A parent element to render the portal element into.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Backdrop>

An overlay displayed beneath the popup. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Positioner>

Positions the popup against the input or trigger. Renders a <div> element.

PropTypeDefault
anchor| Element | null | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null)—

An element to position the popup against. By default, the popup will be positioned against the trigger.

Accepts an element, a virtual element, a ref object, or a function (such as a signal accessor) that returns an element or a virtual element.

positionMethod'absolute' | 'fixed''absolute'

Determines which CSS position property to use.

sideSide'bottom'

Which side of the anchor element to align the popup against. May automatically change to avoid collisions.

sideOffsetnumber | OffsetFunction0

Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.

The function takes a data object parameter with the following properties: - data.anchor: the dimensions of the anchor element with properties width and height. - data.positioner: the dimensions of the positioner element with properties width and height. - data.side: which side of the anchor element the positioner is aligned against. - data.align: how the positioner is aligned relative to the specified side.

alignAlign'center'

How to align the popup relative to the specified side.

alignOffsetnumber | OffsetFunction0

Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.

The function takes a data object parameter with the following properties: - data.anchor: the dimensions of the anchor element with properties width and height. - data.positioner: the dimensions of the positioner element with properties width and height. - data.side: which side of the anchor element the positioner is aligned against. - data.align: how the positioner is aligned relative to the specified side.

collisionBoundaryBoundary'clipping-ancestors'

An element or a rectangle that delimits the area that the popup is confined to.

collisionPaddingPadding5

Additional space to maintain from the edge of the collision boundary.

stickybooleanfalse

Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.

arrowPaddingnumber5

Minimum distance to maintain between the arrow and the edges of the popup.

Use it to prevent the arrow element from hanging out of the rounded corners of a popup.

disableAnchorTrackingbooleanfalse

Whether to disable the popup from tracking any layout shift of its positioning anchor.

collisionAvoidanceCollisionAvoidance—

Determines how to handle collisions when positioning the popup.

side controls overflow on the preferred placement axis (top/bottom or left/right): - 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right). - 'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible. - 'none': do not correct side-axis overflow.

align controls overflow on the alignment axis (start/center/end): - 'flip': keep side, but swap start and end when the requested alignment overflows. - 'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit. - 'none': do not correct alignment-axis overflow.

fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit: - 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR). - 'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR). - 'none': do not fallback to the perpendicular axis.

When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-empty

Present when the items list is empty.

CSS variableDescription
--available-width

The available width between the trigger and the edge of the viewport.

--available-height

The available height between the trigger and the edge of the viewport.

--anchor-width

The anchor's width.

--anchor-height

The anchor's height.

--transform-origin

The coordinates that this element is anchored to. Used for animations and transitions.

<Combobox.Popup>

A container for the list. Renders a <div> element.

PropTypeDefault
initialFocusFocusTargetProp—

Determines the element to focus when the popup is opened.

- false: Do not move focus. - true: Move focus based on the default behavior (first tabbable element or popup). - An element or a ref object ({ current }): Move focus to that element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.

finalFocusFocusTargetProp—

Determines the element to focus when the popup is closed.

- false: Do not move focus. - true: Move focus based on the default behavior (trigger or previously focused element). - An element or a ref object ({ current }): Move focus to that element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-empty

Present when the items list is empty.

<Combobox.Arrow>

Displays an element positioned against the anchor. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-uncentered

Present when the arrow is uncentered.

<Combobox.Icon>

An icon that indicates that the trigger button opens the popup. Renders a <span> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Group>

Groups related items with the corresponding label. Renders a <div> element.

PropTypeDefault
itemsreadonly any[]—

Items to be rendered within this group. When provided, child Collection components will use these items.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.GroupLabel>

An accessible label that is automatically associated with its parent group. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Item>

An individual item in the list. Renders a <div> element.

PropTypeDefault
onClickBaseUIComponentProps<'div', ComboboxItemState>['onClick']—

An optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing Enter with the keyboard if the item is highlighted when the Input or List element has focus.

indexnumber—

The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.

valueanynull

A unique value that identifies this item.

disabledbooleanfalse

Whether the component should ignore user interaction.

nativeButtonbooleanfalse

Whether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-selected

Present when the item is selected.

data-highlighted

Present when the item is highlighted.

data-disabled

Present when the item is disabled.

<Combobox.ItemIndicator>

Indicates whether the item is selected. Renders a <span> element.

PropTypeDefault
keepMountedbooleanfalse

Whether to keep the HTML element in the DOM when the item is not selected.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Chips>

A container for the chips in a multiselectable input. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Chip>

An individual chip that represents a value in a multiselectable input. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.ChipRemove>

A button to remove a chip. Renders a <button> element.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

nativeButtonbooleantrue

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Row>

Displays a single row of items in a grid list. Enable grid on the root component to turn the listbox into a grid. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Collection>

Renders filtered list items. Doesn't render its own HTML element.

If rendering a flat list, pass a function child to the List component instead, which implicitly wraps it.

<Combobox.Empty>

Renders its children only when the list is empty. Requires the items prop on the root component. Announces changes politely to screen readers. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Combobox.Clear>

Clears the value when clicked. Renders a <button> element.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

keepMountedbooleanfalse

Whether the component should remain mounted in the DOM when not visible.

nativeButtonbooleantrue

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the button is disabled.

data-visible

Present when the clear button is visible.

<Combobox.Separator>

A separator element accessible to screen readers. Renders a <div> element.

PropTypeDefault
orientationOrientation'horizontal'

The orientation of the separator.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

useFilter#

Matches items against a query using Intl.Collator for robust string matching. This hook is used when externally filtering items. Pass the result to the filter prop of <Combobox.Root>.

const { contains, startsWith, endsWith } = Combobox.useFilter({ sensitivity: 'base' });

It accepts the Intl.Collator options plus locale, and multiple and value to match the root's selection mode.

useFilteredItems#

Returns an accessor for the internally filtered items when called inside <Combobox.Root>.

const filteredItems = Combobox.useFilteredItems<Fruit>();

<For each={filteredItems()}>{/* ... */}</For>;

createItems#

Normalizes items into a collection for the items prop of <Combobox.Root>, deriving each item's selection value and label before rendering.

Combobox.createItems(data, { getValue, getLabel });
  • data: the flat or grouped source items, or undefined while they are loading. Items cannot have an items array property, because it marks a group.
  • getValue(item): projects an item to the primitive value that identifies it, used as the item's selection value. Each item must derive a unique value.
  • getLabel(item): projects an item to the label shown in the input and used when matching the typed query.