SearchableChipSelect

A low-level primitive for a searchable multi-selection field with chips, with support for a creatable footer action.

Prefer SearchableChipSelectControl when using with a standard label and description.

import { SearchableChipSelect } from '@wordpress/ui';

View on Storybook

View source on GitHub

PropsPermalink to this section

NameDefaultDescription
form

string

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

filter

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

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.

disabledfalse

boolean

Whether the component should ignore user interaction.

name

string

Identifies the field when a form is submitted.

value

Item[] | null | undefined

The selected value of the combobox. Use when controlled.

defaultValue

Item[] | null | undefined

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

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

id

string

The id of the component.

gridfalse

boolean

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

inlinefalse

boolean

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>

In a Combobox.Root > Dialog.Root composition, bind the Combobox’s open and onOpenChange props to the Dialog‘s open and onOpenChange state instead so the component resets its transient state (filter query, highlighted item, and input value) when the dialog closes.

open

boolean

Whether the popup is currently open. Use when controlled.

autoComplete

string

Provides a hint to the browser for autofill.

readOnlyfalse

boolean

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

requiredfalse

boolean

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

defaultOpenfalse

boolean

Whether the popup is initially open.

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

limit-1

number

The maximum number of items to display in the list.

locale

LocalesArgument

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

onValueChange

(value: Item[], eventDetails: ChangeEventDetails) => void

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

onOpenChange

(open: boolean, eventDetails: ChangeEventDetails) => void

Event handler called when the popup is opened or closed.

itemToStringValue

(itemValue: Item) => 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: Item, value: Item) => 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.

inputValue

string | number | readonly string[] | undefined

The input value of the combobox. Use when controlled.

defaultInputValue

string | number | readonly string[] | undefined

The uncontrolled input value when initially rendered.

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

onInputValueChange

(inputValue: string, eventDetails: ChangeEventDetails) => void

Event handler called when the input value changes.

itemToStringLabel

(itemValue: Item) => 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.

autoHighlightfalse

boolean

Whether the first matching item is highlighted automatically while filtering.

highlightItemOnHovertrue

boolean

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

actionsRef

RefObject<Actions | null>

A ref to imperative actions.

  • unmount: Manually unmounts the combobox. Call this after any externally controlled closing animation finishes.
openOnInputClicktrue

boolean

Whether the popup opens when clicking the input.

filteredItems

readonly Item[] | readonly Group<Item>[] | undefined

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.

onOpenChangeComplete

(open: boolean) => void

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

loopFocustrue

boolean

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>.

onItemHighlighted

(highlightedValue: Item | undefined, eventDetails: 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.
  • 'none': the highlight changed programmatically.
inputRef

Ref<HTMLInputElement> | undefined

A ref to the hidden input element.

virtualizedfalse

boolean

Whether the items are being externally virtualized.

modalfalse

boolean

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.

On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.

aria-describedby

string

Identifies the element (or elements) that describes the object.

aria-label

string

Defines a string value that labels the current element.

aria-labelledby

string

Identifies the element (or elements) that labels the current element.

popupWidth'anchor'

"content" | "anchor" | "sm" | "md" | "lg" | "available"

Controls how the popup width is constrained relative to its anchor.

For all presets, the popup is never narrower than its anchor.

  • 'anchor': Fixed width matching the anchor width.
  • 'content': Width grows with item labels between the anchor and available viewport bounds.
  • 'sm': Fixed width at the small surface width token (--wpds-dimension-surface-width-sm).
  • 'md': Fixed width at the medium surface width token (--wpds-dimension-surface-width-md).
  • 'lg': Fixed width at the large surface width token (--wpds-dimension-surface-width-lg).
  • 'available': Fixed width at the available viewport width (--available-width).
items

Item[] | ItemGroup[] | undefined

The array of option items.

When using grouped children, pass an array of groups instead of a flat list of items. Grouped items require a custom children renderer.

Mark a creatable action with creatable: true. It renders in the list footer, not the main list, when it is in the filtered items. Handle the creation of the item in onValueChange.

children

(item: any, index: number) => ReactNode

A render function for custom rendering the list of matching items. Required when items contains groups.

chipsContent

(value: Item[]) => ReactNode

A render function for custom rendering the selected chips.

chipsContent={ ( value ) =>
  value.map( ( item ) => (

  ) )
}
emptyContent__( 'No results found.' )

ReactNode

The custom content to use instead of the default empty state, which shows whenever there are no matching items.

statusContent

ReactNode

Content for the list status live region. The region stays mounted.

searchPlaceholder__( 'Search' )

string

The placeholder text to use for the search input.

showClearButtontrue

boolean

Whether to show the clear button to remove all selected items.

clearButtonLabel__( 'Clear all' )

string

The aria-label for the clear button.

ref

LegacyRef<HTMLInputElement> | undefined

Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

key

Key | null | undefined

ExamplesPermalink to this section

DefaultPermalink to this section

const Default = () => <SearchableChipSelect
    defaultValue={[ ITEMS[ 0 ], ITEMS[ 1 ] ]}
    items={ITEMS}
    aria-label="Fruit" />;

With Custom Chips And ItemsPermalink to this section

To customize what is rendered inside the chips, pass a render function to the chipsContent prop that returns an array of ChipWithRemove subcomponents.

The item list can be customized by passing a render function as children, returning an Item subcomponent for each item.

const WithCustomChipsAndItems = () => <SearchableChipSelect
    chipsContent={( value: typeof ITEMS ) =>
        value.map( ( item ) => (
            <SearchableChipSelect.ChipWithRemove
                key={ item.value }
                prefix={
                    <img
                        src={ `https://gravatar.com/avatar/?d=initials&initials=${ item.label }` }
                        alt=""
                        style={ { width: '100%' } }
                    />
                }
            >
                { item.label }
            </SearchableChipSelect.ChipWithRemove>
        ) )}>{( item: ( typeof ITEMS )[ 0 ] ) => (
        <SearchableChipSelect.Item key={ item.value } value={ item }>
            😋 { item.label }
        </SearchableChipSelect.Item>
    )}</SearchableChipSelect>;

With Custom Empty ContentPermalink to this section

Use the emptyContent prop to customize the empty state, which shows whenever there are no matching items.

const WithCustomEmptyContent = () => <SearchableChipSelect emptyContent="No fruit found 🥺" />;

GroupedPermalink to this section

To render grouped items, pass an array of groups to items (each with label and items properties) and provide children that renders each group using SearchableChipSelect.Group, SearchableChipSelect.GroupLabel, and SearchableChipSelect.Collection. Grouped items have no default renderer, so children is required.

const Grouped = () => <SearchableChipSelect aria-label="Fruit" items={GROUPED_ITEMS}>{( group: FixtureGroup ) => (
        <SearchableChipSelect.Group
            key={ group.label }
            items={ group.items }
        >
            <SearchableChipSelect.GroupLabel>
                { group.label }
            </SearchableChipSelect.GroupLabel>
            <SearchableChipSelect.Collection>
                { ( item: FixtureItem ) => (
                    <SearchableChipSelect.Item
                        key={ item.value }
                        value={ item }
                    >
                        { item.label }
                    </SearchableChipSelect.Item>
                ) }
            </SearchableChipSelect.Collection>
        </SearchableChipSelect.Group>
    )}</SearchableChipSelect>;

Without Clear ButtonPermalink to this section

Use the showClearButton prop to hide the clear button.

const WithoutClearButton = () => <SearchableChipSelect showClearButton={false} />;