Repository navigation
SearchableChipSelect: Add grouped items support #80989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 ff0f62f
Add changelog
mirka 4cab49a
SearchableChipSelect: Use controlled creatableItem pattern.
mirka e9b7452
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka bc142b9
Clarify grouped case instructions
mirka a43ae50
SearchableChipSelect: Add default renderer and grouped selection tests.
mirka d4589d2
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka 29c2344
Add breaking change changelog
mirka 00c8530
Use a more unique creatable value
mirka 7ea7a3f
SearchableChipSelect: Use creatable item marker.
mirka eb6bf91
SearchableChipSelect: Add development warnings.
mirka 5b70d52
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka cb5302f
SearchableChipSelect: Fix normalizeRootItems type narrowing.
mirka 7b6267c
SearchableChipSelect: Simplify Item type.
mirka 2594db2
Merge branch 'trunk' into update-ui-searchable-chip-select
mirka e192d7c
SearchableChipSelect: Normalize creatable items in grouped lists
mirka 8da3252
Emphasize grouped case in docs
mirka 0bdee85
SearchableChipSelect: Drop redundant creatable order warning
mirka b3517f9
SearchableChipSelect: Move test fixtures out of stories
mirka 1a4b479
SearchableChipSelect: Keep test fixtures out of Jest path
mirka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/ui/src/form/primitives/searchable-chip-select/dev-warnings.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.' | ||
| ); | ||
| } | ||
| } |
10 changes: 9 additions & 1 deletion
10
packages/ui/src/form/primitives/searchable-chip-select/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
|
|
||
| export const SearchableChipSelect = Object.assign( _SearchableChipSelect, { | ||
| Item, | ||
| ChipWithRemove, | ||
| Group, | ||
| GroupLabel, | ||
| Collection, | ||
| } ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/ui/src/form/primitives/searchable-chip-select/test/__fixtures__/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' }, | ||
| ], | ||
| }, | ||
| ]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Collectionsubcomponent, but already effects other subcomponents as well.Longer answer
When higher-level components re-export combobox subcomponents (
Item,Group,Collection, etc.) and assigndisplayNamein each layer's index file, two issues stack up:1. TypeScript vs runtime
forwardRefsubcomponents (Item,Group, …) allowdisplayNameassignment. Plain functions likeCollectiondon't — TypeScript errors unless you suppress or cast.forwardRefonCollectiondoesn't work because base-ui'sCollectiondoesn't take a ref.2. Shared singleton references
Re-exporting the same imported component and setting
displayNamein bothSearchableChipSelectandSearchableChipSelectControlmutates one function object — only the last assignment wins. That's already true forItem,Group, etc., not justCollection.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.displayNamefor now; treat the singleton / multi-layer naming problem as systemic, not worth solving piecemeal in this PR.