Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b533f9c
SearchableChipSelect: Add grouped items support.
mirka Jul 30, 2026
ff0f62f
Add changelog
mirka Jul 30, 2026
4cab49a
SearchableChipSelect: Use controlled creatableItem pattern.
mirka Jul 31, 2026
e9b7452
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka Aug 3, 2026
bc142b9
Clarify grouped case instructions
mirka Aug 3, 2026
a43ae50
SearchableChipSelect: Add default renderer and grouped selection tests.
mirka Aug 6, 2026
d4589d2
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka Aug 7, 2026
29c2344
Add breaking change changelog
mirka Aug 7, 2026
00c8530
Use a more unique creatable value
mirka Aug 7, 2026
7ea7a3f
SearchableChipSelect: Use creatable item marker.
mirka Aug 12, 2026
eb6bf91
SearchableChipSelect: Add development warnings.
mirka Aug 12, 2026
5b70d52
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka Aug 12, 2026
cb5302f
SearchableChipSelect: Fix normalizeRootItems type narrowing.
mirka Aug 12, 2026
7b6267c
SearchableChipSelect: Simplify Item type.
mirka Aug 13, 2026
2594db2
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka Aug 21, 2026
e192d7c
SearchableChipSelect: Normalize creatable items in grouped lists
mirka Aug 21, 2026
8da3252
Emphasize grouped case in docs
mirka Aug 21, 2026
0bdee85
SearchableChipSelect: Drop redundant creatable order warning
mirka Aug 21, 2026
b3517f9
SearchableChipSelect: Move test fixtures out of stories
mirka Aug 21, 2026
1a4b479
SearchableChipSelect: Keep test fixtures out of Jest path
mirka Aug 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Breaking Changes

- `SearchableChipSelect`: Remove the `creatableItem` prop. Mark a creatable action with `creatable: true` on an item in `items` instead. The item renders in the list footer and is excluded from the main list automatically. Handle selection in `onValueChange`. See the `Creatable` and `GroupedCreatable` stories for examples ([#80989](https://github.com/WordPress/gutenberg/pull/80989)).
- `Select.Item`: Remove `'compact'` from the `size` prop. Use `'default'` instead ([#81354](https://github.com/WordPress/gutenberg/pull/81354)).
- `Combobox.Item`, `SelectControl.Item`: The `size` prop is removed ([#81354](https://github.com/WordPress/gutenberg/pull/81354)).

Expand All @@ -19,6 +20,8 @@
- Add `TextareaControl` component ([#81359](https://github.com/WordPress/gutenberg/pull/81359)).
- Export shared keyboard shortcut presentation and accessibility utilities. ([#81826](https://github.com/WordPress/gutenberg/pull/81826))
- `Menu`: Add shortcut display and accessibility metadata support. ([#79560](https://github.com/WordPress/gutenberg/pull/79560))
- `SearchableChipSelect`: Add grouped items support and export `Group`, `GroupLabel`, and `Collection` subcomponents ([#80989](https://github.com/WordPress/gutenberg/pull/80989)).
- `SearchableChipSelect`: Add development warnings for common misconfigurations ([#80989](https://github.com/WordPress/gutenberg/pull/80989)).
- `Select.Item`, `Combobox.Item`, and `Autocomplete.Item`: Default item height is now 32px (previously 40px) ([#81354](https://github.com/WordPress/gutenberg/pull/81354)).
- `InputLayout`-based controls show an error-colored border and focus ring while an invalid control's validity is reported, e.g. when wrapped in `ControlWithError` ([#81230](https://github.com/WordPress/gutenberg/issues/81230)) ([#81574](https://github.com/WordPress/gutenberg/pull/81574)).

Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/style-runtime": "file:../style-runtime",
"@wordpress/theme": "file:../theme",
"@wordpress/warning": "file:../warning",
"clsx": "^2.1.1",
"date-fns": "^4.4.0",
"tabbable": "^6.4.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import warning from '@wordpress/warning';
import type { ComboboxCollectionProps } from '../combobox/types';
import {
findCreatableItems,
hasGroupedItems,
type Item,
type ItemGroup,
} from './types';

export function warnSearchableChipSelectProps(
items: Item[] | ItemGroup[] | undefined,
children: ComboboxCollectionProps[ 'children' ] | undefined
): void {
if ( ! items?.length ) {
return;
}

const creatableItems = findCreatableItems( items );

if ( creatableItems.length > 1 ) {
warning(
'SearchableChipSelect: expected at most one item with `creatable: true` in `items`.'
);
}

if ( hasGroupedItems( items ) && ! children ) {
warning(
'SearchableChipSelect: grouped `items` require a `children` renderer. See the `Grouped` story for an example.'
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { ChipWithRemove } from '../combobox/chip-with-remove';
import { Item } from '../combobox/item';
import { ChipWithRemove } from '../combobox/chip-with-remove';
import { Group } from '../combobox/group';
import { GroupLabel } from '../combobox/group-label';
import { Collection } from '../combobox/collection';
import { SearchableChipSelect as _SearchableChipSelect } from './searchable-chip-select';

Item.displayName = 'SearchableChipSelect.Item';
ChipWithRemove.displayName = 'SearchableChipSelect.ChipWithRemove';
Group.displayName = 'SearchableChipSelect.Group';
GroupLabel.displayName = 'SearchableChipSelect.GroupLabel';
Comment on lines 8 to +11

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we setting a display name for Collection?

Short answer: I realized we have some systemic problems with the way we assign new display names on re-exports. This is especially noticeable for the Collection subcomponent, but already effects other subcomponents as well.

Longer answer

When higher-level components re-export combobox subcomponents (Item, Group, Collection, etc.) and assign displayName in each layer's index file, two issues stack up:

1. TypeScript vs runtime
forwardRef subcomponents (Item, Group, …) allow displayName assignment. Plain functions like Collection don't — TypeScript errors unless you suppress or cast. forwardRef on Collection doesn't work because base-ui's Collection doesn't take a ref.

2. Shared singleton references
Re-exporting the same imported component and setting displayName in both SearchableChipSelect and SearchableChipSelectControl mutates one function object — only the last assignment wins. That's already true for Item, Group, etc., not just Collection.

Distinct names per layer requires a new component reference each time — a wrapper function or a dedicated file (like SelectControl.Item, which wraps rather than re-exports).

Decision: Skip Collection.displayName for now; treat the singleton / multi-layer naming problem as systemic, not worth solving piecemeal in this PR.


export const SearchableChipSelect = Object.assign( _SearchableChipSelect, {
Item,
ChipWithRemove,
Group,
GroupLabel,
Collection,
} );
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import focusStyles from '../../../utils/css/focus.module.scss';
import * as Combobox from '../combobox';
import { InputLayout } from '../input-layout';
import styles from './style.module.css';
import type { Item, SearchableChipSelectProps } from './types';
import { warnSearchableChipSelectProps } from './dev-warnings';
import type { Item, ItemGroup, SearchableChipSelectProps } from './types';
import {
findCreatableItem,
isItem,
normalizeRootItems,
shouldSkipCollectionEntry,
} from './types';

/**
* A searchable multi-selection component with chips, with support for
Expand All @@ -19,7 +26,6 @@ export const SearchableChipSelect = forwardRef<
>( function SearchableChipSelect(
{
children,
creatableItem,
disabled,
emptyContent = __( 'No results found.' ),
items,
Expand All @@ -34,11 +40,14 @@ export const SearchableChipSelect = forwardRef<
},
ref
) {
warnSearchableChipSelectProps( items, children );

const creatableItem = findCreatableItem( items );
const comboboxItems = normalizeRootItems( items );

return (
<Combobox.Root
items={
! creatableItem ? items : [ ...( items ?? [] ), creatableItem ]
}
items={ comboboxItems }
multiple
disabled={ disabled }
{ ...restProps }
Expand Down Expand Up @@ -114,20 +123,31 @@ export const SearchableChipSelect = forwardRef<
<Combobox.List>
<Combobox.ListBody>
<Combobox.Collection>
{ ( item: Item, ...args ) => {
if ( item.value === creatableItem?.value ) {
{ ( entry: Item | ItemGroup, ...args ) => {
if (
shouldSkipCollectionEntry(
entry,
creatableItem
)
) {
return null;
}

if ( children ) {
return children( item, ...args );
return children( entry, ...args );
}

if ( ! isItem( entry ) ) {
return null;
}

return (
<Combobox.Item
key={ item.value }
value={ item }
disabled={ item.disabled }
key={ entry.value }
value={ entry }
disabled={ entry.disabled }
>
{ item.label }
{ entry.label }
</Combobox.Item>
);
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
import { useState } from '@wordpress/element';
import { fn } from 'storybook/test';
import { SearchableChipSelect } from '../';
import {
GROUPED_ITEMS,
type FixtureGroup,
type FixtureItem,
} from '../../combobox/stories/fixtures';
import { ITEMS } from './fixtures';

const meta: Meta< typeof SearchableChipSelect > = {
title: 'Design System/Components/Form/Primitives/SearchableChipSelect',
component: SearchableChipSelect,
subcomponents: {
'SearchableChipSelect.Group': SearchableChipSelect.Group,
'SearchableChipSelect.GroupLabel': SearchableChipSelect.GroupLabel,
'SearchableChipSelect.Item': SearchableChipSelect.Item,
'SearchableChipSelect.ChipWithRemove':
SearchableChipSelect.ChipWithRemove,
'SearchableChipSelect.Collection': SearchableChipSelect.Collection,
},
argTypes: {
items: { control: false },
Expand All @@ -36,11 +44,9 @@ export const Default: Story = {
};

/**
* The `creatableItem` prop is used to add some kind of "Create new item"
* action item to the footer of the list.
*
* In the `onValueChange` function, add some logic to handle the creation of a new item
* whenever the `creatableItem` is selected.
* Mark a creatable action with `creatable: true` on an item in `items`.
* It renders in the list footer and is excluded from the main list
* automatically. Handle creation in `onValueChange`.
*/
export const Creatable: Story = {
args: {
Expand All @@ -53,24 +59,31 @@ export const Creatable: Story = {
ITEMS[ 1 ],
] );
const creatableItem = {
value: 'create',
value: '__create__',
label:
'Create new item' + ( inputValue ? `: ${ inputValue }` : '' ),
creatable: true,
};

return (
<SearchableChipSelect
{ ...args }
creatableItem={ creatableItem }
items={ [ ...ITEMS, creatableItem ] }
inputValue={ inputValue }
onInputValueChange={ setInputValue }
value={ value }
onValueChange={ ( values: typeof ITEMS, event ) => {
if ( values.some( ( item ) => item.value === 'create' ) ) {
if (
values.some(
( item ) => item.value === creatableItem.value
)
) {
// eslint-disable-next-line no-alert
alert( `Create new item: '${ inputValue }'` );
setValue(
values.filter( ( item ) => item.value !== 'create' )
values.filter(
( item ) => item.value !== creatableItem.value
)
);
} else {
setValue( values );
Expand Down Expand Up @@ -126,6 +139,111 @@ export const WithCustomEmptyContent: Story = {
},
};

/**
* 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.
*/
export const Grouped: Story = {
args: {
items: GROUPED_ITEMS,
children: ( 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>
),
},
};

/**
* Grouped items with a creatable footer item. Include the creatable item in
* `items` as a creatable-only group and handle creation in `onValueChange`.
*/
export const GroupedCreatable: Story = {
render: function Template( args ) {
const [ inputValue, setInputValue ] = useState( '' );
const [ value, setValue ] = useState< FixtureItem[] >( [
GROUPED_ITEMS[ 0 ].items[ 0 ],
GROUPED_ITEMS[ 1 ].items[ 0 ],
] );
const creatableItem = {
value: '__create__',
label:
'Create new item' + ( inputValue ? `: ${ inputValue }` : '' ),
creatable: true,
};
const items = [
...GROUPED_ITEMS,
{ label: '', items: [ creatableItem ] },
];

return (
<SearchableChipSelect
{ ...args }
items={ items }
inputValue={ inputValue }
onInputValueChange={ setInputValue }
value={ value }
onValueChange={ ( values: FixtureItem[], event ) => {
if (
values.some(
( item ) => item.value === creatableItem.value
)
) {
// eslint-disable-next-line no-alert
alert( `Create new item: '${ inputValue }'` );
setValue(
values.filter(
( item ) => item.value !== creatableItem.value
)
);
} else {
setValue( values );
}
args.onValueChange?.( values, event );
} }
children={ ( 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>
) }
/>
);
},
};

/**
* Use the `showClearButton` prop to hide the clear button.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Item, ItemGroup } from '../../types';

export const ITEMS: Item[] = [
{ value: 'apple', label: 'Apple' },
{ value: 'apricot', label: 'Apricot' },
{ value: 'banana', label: 'Banana' },
{ value: 'blackberry', label: 'Blackberry' },
{ value: 'blueberry', label: 'Blueberry' },
];

export const GROUPED_ITEMS: ItemGroup[] = [
{
label: 'Common',
items: [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'orange', label: 'Orange' },
],
},
{
label: 'Berries',
items: [
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'blueberry', label: 'Blueberry' },
{ value: 'raspberry', label: 'Raspberry' },
],
},
];
Loading
Loading