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';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
form |
Identifies the form that owns the internal input. Useful when the combobox is rendered outside the form. | |
filter |
Filter function used to match items vs input query.
Receives the source item, which is the derived value’s item when | |
disabled | false |
Whether the component should ignore user interaction. |
name |
Identifies the field when a form is submitted. | |
value |
The selected value of the combobox. Use when controlled. | |
defaultValue |
The uncontrolled selected value of the combobox when it’s initially rendered. To render a controlled combobox, use the | |
id |
The id of the component. | |
grid | false |
Whether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows. |
inline | false |
Whether the list is rendered inline without using the component’s own popup. Specify In a |
open |
Whether the popup is currently open. Use when controlled. | |
autoComplete |
Provides a hint to the browser for autofill. | |
readOnly | false |
Whether the user should be unable to choose a different option from the popup. |
required | false |
Whether the user must choose a value before submitting a form. |
defaultOpen | false |
Whether the popup is initially open. To render a controlled popup, use the |
limit | -1 |
The maximum number of items to display in the list. |
locale |
The locale to use for string comparison. Defaults to the user’s runtime locale. | |
onValueChange |
Event handler called when the selected value of the combobox changes. | |
onOpenChange |
Event handler called when the popup is opened or closed. | |
itemToStringValue |
When the item values are objects ( | |
isItemEqualToValue |
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 | |
inputValue |
The input value of the combobox. Use when controlled. | |
defaultInputValue |
The uncontrolled input value when initially rendered. To render a controlled input, use the | |
onInputValueChange |
Event handler called when the input value changes. | |
itemToStringLabel |
When the item values are objects ( | |
autoHighlight | false |
Whether the first matching item is highlighted automatically while filtering. |
highlightItemOnHover | true |
Whether moving the pointer over items should highlight them.
Disabling this prop allows CSS |
actionsRef |
A ref to imperative actions.
| |
openOnInputClick | true |
Whether the popup opens when clicking the input. |
filteredItems |
Filtered items to display in the list.
When provided, the list uses these items instead of filtering the | |
onOpenChangeComplete |
Event handler called after any animations complete when the popup is opened or closed. | |
loopFocus | true |
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 |
Callback fired when an item is highlighted or unhighlighted.
Receives the highlighted item value (or
| |
inputRef |
A ref to the hidden input element. | |
virtualized | false |
Whether the items are being externally virtualized. |
modal | false |
Determines if the popup enters a modal state when open.
On touch devices, a |
aria-describedby |
Identifies the element (or elements) that describes the object. | |
aria-label |
Defines a string value that labels the current element. | |
aria-labelledby |
Identifies the element (or elements) that labels the current element. | |
popupWidth | 'anchor' |
Controls how the popup width is constrained relative to its anchor. For all presets, the popup is never narrower than its anchor.
|
items |
The array of option items. When using grouped Mark a creatable action with | |
children |
A render function for custom rendering the list of matching items.
Required when | |
chipsContent |
A render function for custom rendering the selected chips. | |
emptyContent | __( 'No results found.' ) |
The custom content to use instead of the default empty state, which shows whenever there are no matching items. |
statusContent |
Content for the list status live region. The region stays mounted. | |
searchPlaceholder | __( 'Search' ) |
The placeholder text to use for the search input. |
showClearButton | true |
Whether to show the clear button to remove all selected items. |
clearButtonLabel | __( 'Clear all' ) |
The aria-label for the clear button. |
ref |
Allows getting a ref to the component instance.
Once the component unmounts, React will set | |
key |
|
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} />;