From b73964c77411c873011df0859e1ebb08284d379c Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Thu, 30 Apr 2026 02:49:27 +0900 Subject: [PATCH 01/34] Add Combobox primitives --- .../primitives/combobox/chip-with-remove.tsx | 50 +++ .../ui/src/form/primitives/combobox/chips.tsx | 9 + .../ui/src/form/primitives/combobox/clear.tsx | 34 ++ .../form/primitives/combobox/collection.tsx | 13 + .../ui/src/form/primitives/combobox/empty.tsx | 17 + .../ui/src/form/primitives/combobox/index.ts | 15 + .../ui/src/form/primitives/combobox/input.tsx | 26 ++ .../ui/src/form/primitives/combobox/item.tsx | 41 +++ .../form/primitives/combobox/list-body.tsx | 23 ++ .../form/primitives/combobox/list-footer.tsx | 24 ++ .../ui/src/form/primitives/combobox/list.tsx | 17 + .../ui/src/form/primitives/combobox/popup.tsx | 42 +++ .../src/form/primitives/combobox/portal.tsx | 16 + .../ui/src/form/primitives/combobox/root.tsx | 14 + .../primitives/combobox/stories/fixtures.ts | 57 +++ .../combobox/stories/index.story.tsx | 348 ++++++++++++++++++ .../form/primitives/combobox/style.module.css | 72 ++++ .../primitives/combobox/test/index.test.tsx | 307 +++++++++++++++ .../src/form/primitives/combobox/trigger.tsx | 56 +++ .../ui/src/form/primitives/combobox/types.ts | 92 +++++ .../ui/src/form/primitives/combobox/value.tsx | 6 + packages/ui/src/form/primitives/index.ts | 1 + 22 files changed, 1280 insertions(+) create mode 100644 packages/ui/src/form/primitives/combobox/chip-with-remove.tsx create mode 100644 packages/ui/src/form/primitives/combobox/chips.tsx create mode 100644 packages/ui/src/form/primitives/combobox/clear.tsx create mode 100644 packages/ui/src/form/primitives/combobox/collection.tsx create mode 100644 packages/ui/src/form/primitives/combobox/empty.tsx create mode 100644 packages/ui/src/form/primitives/combobox/index.ts create mode 100644 packages/ui/src/form/primitives/combobox/input.tsx create mode 100644 packages/ui/src/form/primitives/combobox/item.tsx create mode 100644 packages/ui/src/form/primitives/combobox/list-body.tsx create mode 100644 packages/ui/src/form/primitives/combobox/list-footer.tsx create mode 100644 packages/ui/src/form/primitives/combobox/list.tsx create mode 100644 packages/ui/src/form/primitives/combobox/popup.tsx create mode 100644 packages/ui/src/form/primitives/combobox/portal.tsx create mode 100644 packages/ui/src/form/primitives/combobox/root.tsx create mode 100644 packages/ui/src/form/primitives/combobox/stories/fixtures.ts create mode 100644 packages/ui/src/form/primitives/combobox/stories/index.story.tsx create mode 100644 packages/ui/src/form/primitives/combobox/style.module.css create mode 100644 packages/ui/src/form/primitives/combobox/test/index.test.tsx create mode 100644 packages/ui/src/form/primitives/combobox/trigger.tsx create mode 100644 packages/ui/src/form/primitives/combobox/types.ts create mode 100644 packages/ui/src/form/primitives/combobox/value.tsx diff --git a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx new file mode 100644 index 00000000000000..f96f772d607fe9 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx @@ -0,0 +1,50 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import { forwardRef } from '@wordpress/element'; +import clsx from 'clsx'; +import { __ } from '@wordpress/i18n'; +import { closeSmall } from '@wordpress/icons'; +import { IconButton } from '../../../icon-button'; +import type { ComboboxChipWithRemoveProps } from './types'; +import styles from './style.module.css'; + +/** + * A utility component that combines a chip and a remove button, + * with standard styling. + * + * For custom designs, use the `Combobox.Chip` and `Combobox.ChipRemove` + * components directly. + */ +export const ChipWithRemove = forwardRef< + HTMLDivElement, + ComboboxChipWithRemoveProps +>( function Clear( { className, children, prefix, ...restProps }, ref ) { + return ( + <_Combobox.Chip + ref={ ref } + className={ clsx( styles.chip, className ) } + { ...restProps } + > + { prefix && ( + { prefix } + ) } + { children } + + <_Combobox.ChipRemove + className={ styles[ 'chip-remove' ] } + render={ ( props, { disabled } ) => ( + + ) } + /> + + ); +} ); diff --git a/packages/ui/src/form/primitives/combobox/chips.tsx b/packages/ui/src/form/primitives/combobox/chips.tsx new file mode 100644 index 00000000000000..fe0b75c49f087d --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/chips.tsx @@ -0,0 +1,9 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import { forwardRef } from '@wordpress/element'; +import type { ComboboxChipsProps } from './types'; + +export const Chips = forwardRef< HTMLDivElement, ComboboxChipsProps >( + function Chips( props, ref ) { + return <_Combobox.Chips ref={ ref } { ...props } />; + } +); diff --git a/packages/ui/src/form/primitives/combobox/clear.tsx b/packages/ui/src/form/primitives/combobox/clear.tsx new file mode 100644 index 00000000000000..5ae7cde96357ab --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/clear.tsx @@ -0,0 +1,34 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import { forwardRef } from '@wordpress/element'; +import { closeSmall } from '@wordpress/icons'; +import { __ } from '@wordpress/i18n'; +import { IconButton } from '../../../icon-button'; +import type { ComboboxClearProps } from './types'; + +const DEFAULT_RENDER = ( + { 'aria-label': ariaLabel = __( 'Clear' ), ...props }: ComboboxClearProps, + { disabled }: _Combobox.Clear.State +) => ( + +); + +/** + * A button that clears the selected value(s). + */ +export const Clear = forwardRef< HTMLButtonElement, ComboboxClearProps >( + function Clear( { render = DEFAULT_RENDER, ...restProps }, ref ) { + return ( + <_Combobox.Clear ref={ ref } render={ render } { ...restProps } /> + ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/collection.tsx b/packages/ui/src/form/primitives/combobox/collection.tsx new file mode 100644 index 00000000000000..f94a9ab85189be --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/collection.tsx @@ -0,0 +1,13 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import type { ComboboxCollectionProps } from './types'; + +export function Collection( { + children, + ...restProps +}: ComboboxCollectionProps ) { + return ( + <_Combobox.Collection { ...restProps }> + { children } + + ); +} diff --git a/packages/ui/src/form/primitives/combobox/empty.tsx b/packages/ui/src/form/primitives/combobox/empty.tsx new file mode 100644 index 00000000000000..0096920d2d156a --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/empty.tsx @@ -0,0 +1,17 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import clsx from 'clsx'; +import { forwardRef } from '@wordpress/element'; +import type { ComboboxEmptyProps } from './types'; +import itemPopupStyles from '../../../utils/css/item-popup.module.css'; + +export const Empty = forwardRef< HTMLDivElement, ComboboxEmptyProps >( + function Empty( { className, ...restProps }, ref ) { + return ( + <_Combobox.Empty + className={ clsx( itemPopupStyles.empty, className ) } + ref={ ref } + { ...restProps } + /> + ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/index.ts b/packages/ui/src/form/primitives/combobox/index.ts new file mode 100644 index 00000000000000..53c9468b239825 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/index.ts @@ -0,0 +1,15 @@ +export { Chips } from './chips'; +export { ChipWithRemove } from './chip-with-remove'; +export { Clear } from './clear'; +export { Collection } from './collection'; +export { Empty } from './empty'; +export { Input } from './input'; +export { Item } from './item'; +export { List } from './list'; +export { ListBody } from './list-body'; +export { ListFooter } from './list-footer'; +export { Portal } from './portal'; +export { Popup } from './popup'; +export { Root } from './root'; +export { Trigger } from './trigger'; +export { Value } from './value'; diff --git a/packages/ui/src/form/primitives/combobox/input.tsx b/packages/ui/src/form/primitives/combobox/input.tsx new file mode 100644 index 00000000000000..bb3048342bfe12 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/input.tsx @@ -0,0 +1,26 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import { forwardRef } from '@wordpress/element'; +import { search } from '@wordpress/icons'; +import { Icon } from '../../../icon'; +import { Input as InputPrimitive } from '../input'; +import { InputLayout } from '../input-layout'; +import type { ComboboxInputProps } from './types'; + +const DEFAULT_RENDER = ( props: ComboboxInputProps ) => ( + + + + } + { ...props } + /> +); + +export const Input = forwardRef< HTMLInputElement, ComboboxInputProps >( + function Input( { render = DEFAULT_RENDER, ...restProps }, ref ) { + return ( + <_Combobox.Input ref={ ref } render={ render } { ...restProps } /> + ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/item.tsx b/packages/ui/src/form/primitives/combobox/item.tsx new file mode 100644 index 00000000000000..11f63605f184f7 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/item.tsx @@ -0,0 +1,41 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import clsx from 'clsx'; +import { forwardRef } from '@wordpress/element'; +import { check, plus } from '@wordpress/icons'; +import { Icon } from '../../../icon'; +import itemPopupStyles from '../../../utils/css/item-popup.module.css'; +import resetStyles from '../../../utils/css/resets.module.css'; +import type { ComboboxItemProps } from './types'; + +export const Item = forwardRef< HTMLDivElement, ComboboxItemProps >( + function Item( + { className, children, variant = 'default', ...restProps }, + ref + ) { + return ( + <_Combobox.Item + className={ clsx( + resetStyles[ 'box-sizing' ], + itemPopupStyles.item, + itemPopupStyles[ `is-${ variant }` ], + className + ) } + ref={ ref } + { ...restProps } + > + { variant === 'creatable' ? ( + + ) : ( + + ) } + { children } + + ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/list-body.tsx b/packages/ui/src/form/primitives/combobox/list-body.tsx new file mode 100644 index 00000000000000..903f3bf4464213 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/list-body.tsx @@ -0,0 +1,23 @@ +import { forwardRef } from '@wordpress/element'; +import { mergeProps, useRender } from '@base-ui/react'; +import type { ComboboxListBodyProps } from './types'; +import itemPopupStyles from '../../../utils/css/item-popup.module.css'; + +/** + * A layout container for the main scrolling area in the `List`, for holding `Item`s. + */ +export const ListBody = forwardRef< HTMLDivElement, ComboboxListBodyProps >( + function ListBody( { render, ...props }, ref ) { + const element = useRender( { + defaultTagName: 'div', + render, + ref, + props: mergeProps< 'div' >( + { className: itemPopupStyles[ 'list-scrollable-container' ] }, + props + ), + } ); + + return element; + } +); diff --git a/packages/ui/src/form/primitives/combobox/list-footer.tsx b/packages/ui/src/form/primitives/combobox/list-footer.tsx new file mode 100644 index 00000000000000..f572b1f6916f6e --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/list-footer.tsx @@ -0,0 +1,24 @@ +import { forwardRef } from '@wordpress/element'; +import { mergeProps, useRender } from '@base-ui/react'; +import type { ComboboxListFooterProps } from './types'; +import itemPopupStyles from '../../../utils/css/item-popup.module.css'; + +/** + * A layout container for the footer row in the `List`, + * for holding a single `Item` that triggers the creation of a new item. + */ +export const ListFooter = forwardRef< HTMLDivElement, ComboboxListFooterProps >( + function ListFooter( { render, ...props }, ref ) { + const element = useRender( { + defaultTagName: 'div', + render, + ref, + props: mergeProps< 'div' >( + { className: itemPopupStyles[ 'list-footer' ] }, + props + ), + } ); + + return element; + } +); diff --git a/packages/ui/src/form/primitives/combobox/list.tsx b/packages/ui/src/form/primitives/combobox/list.tsx new file mode 100644 index 00000000000000..afbf930bff303b --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/list.tsx @@ -0,0 +1,17 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import clsx from 'clsx'; +import { forwardRef } from '@wordpress/element'; +import type { ComboboxListProps } from './types'; +import itemPopupStyles from '../../../utils/css/item-popup.module.css'; + +export const List = forwardRef< HTMLDivElement, ComboboxListProps >( + function List( { className, ...restProps }, ref ) { + return ( + <_Combobox.List + className={ clsx( itemPopupStyles.list, className ) } + ref={ ref } + { ...restProps } + /> + ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/popup.tsx b/packages/ui/src/form/primitives/combobox/popup.tsx new file mode 100644 index 00000000000000..853ff393a686bd --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/popup.tsx @@ -0,0 +1,42 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import clsx from 'clsx'; +import { forwardRef } from '@wordpress/element'; +import { + type ThemeProvider as ThemeProviderType, + privateApis as themePrivateApis, +} from '@wordpress/theme'; +import { unlock } from '../../../lock-unlock'; +import { Portal } from './portal'; +import { renderPortalWithChildren } from '../../../utils/render-portal-with-children'; +import itemPopupStyles from '../../../utils/css/item-popup.module.css'; +import resetStyles from '../../../utils/css/resets.module.css'; +import styles from './style.module.css'; +import type { ComboboxPopupProps } from './types'; +import { ITEM_POPUP_POSITIONER_PROPS } from '../constants'; + +const ThemeProvider: typeof ThemeProviderType = + unlock( themePrivateApis ).ThemeProvider; + +export const Popup = forwardRef< HTMLDivElement, ComboboxPopupProps >( + function Popup( { className, portal, ...restProps }, ref ) { + const portalChildren = ( + <_Combobox.Positioner + { ...ITEM_POPUP_POSITIONER_PROPS } + className={ clsx( + resetStyles[ 'box-sizing' ], + styles.positioner + ) } + > + + <_Combobox.Popup + ref={ ref } + className={ clsx( itemPopupStyles.popup, className ) } + { ...restProps } + /> + + + ); + + return renderPortalWithChildren( portal, , portalChildren ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/portal.tsx b/packages/ui/src/form/primitives/combobox/portal.tsx new file mode 100644 index 00000000000000..05d509fa18ee60 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/portal.tsx @@ -0,0 +1,16 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import { forwardRef } from '@wordpress/element'; +import type { PortalProps } from './types'; + +/** + * Root element that portals `Combobox` popup content. Pass to + * `Combobox.Popup`'s `portal` prop. When `portal` is omitted, + * `Combobox.Popup` uses this component with default props. + */ +const Portal = forwardRef< HTMLDivElement, PortalProps >( + function ComboboxPortal( props, ref ) { + return <_Combobox.Portal ref={ ref } { ...props } />; + } +); + +export { Portal }; diff --git a/packages/ui/src/form/primitives/combobox/root.tsx b/packages/ui/src/form/primitives/combobox/root.tsx new file mode 100644 index 00000000000000..7bbcf14d9062a5 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/root.tsx @@ -0,0 +1,14 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import type { ComboboxRootProps } from './types'; + +/** + * Low-level primitive for a combobox that has an associated selection state. + * + * See `SearchableSelectControl` and `SearchableChipSelectControl` for standard + * implementations of a single and multiple selection combobox. + */ +export function Root< Value, Multiple extends boolean | undefined = false >( + props: ComboboxRootProps< Value, Multiple > +) { + return <_Combobox.Root { ...props } />; +} diff --git a/packages/ui/src/form/primitives/combobox/stories/fixtures.ts b/packages/ui/src/form/primitives/combobox/stories/fixtures.ts new file mode 100644 index 00000000000000..88625e26db6040 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/stories/fixtures.ts @@ -0,0 +1,57 @@ +export interface FixtureItem { + id: string; + value: string; +} + +export const ITEMS: FixtureItem[] = [ + { id: 'apple', value: 'Apple' }, + { id: 'apricot', value: 'Apricot' }, + { id: 'banana', value: 'Banana' }, + { id: 'blackberry', value: 'Blackberry' }, + { id: 'blueberry', value: 'Blueberry' }, + { id: 'boysenberry', value: 'Boysenberry' }, + { id: 'breadfruit', value: 'Breadfruit' }, + { id: 'cantaloupe', value: 'Cantaloupe' }, + { id: 'cherry', value: 'Cherry' }, + { id: 'clementine', value: 'Clementine' }, + { id: 'coconut', value: 'Coconut' }, + { id: 'cranberry', value: 'Cranberry' }, + { id: 'dragonfruit', value: 'Dragonfruit' }, + { id: 'durian', value: 'Durian' }, + { id: 'elderberry', value: 'Elderberry' }, + { id: 'fig', value: 'Fig' }, + { id: 'gooseberry', value: 'Gooseberry' }, + { id: 'grape', value: 'Grape' }, + { id: 'grapefruit', value: 'Grapefruit' }, + { id: 'guava', value: 'Guava' }, + { id: 'honeydew', value: 'Honeydew' }, + { id: 'jackfruit', value: 'Jackfruit' }, + { id: 'kiwi', value: 'Kiwi' }, + { id: 'kumquat', value: 'Kumquat' }, + { id: 'lemon', value: 'Lemon' }, + { id: 'lime', value: 'Lime' }, + { id: 'longan', value: 'Longan' }, + { id: 'lychee', value: 'Lychee' }, + { id: 'mandarin', value: 'Mandarin' }, + { id: 'mango', value: 'Mango' }, + { id: 'mangosteen', value: 'Mangosteen' }, + { id: 'mulberry', value: 'Mulberry' }, + { id: 'nectarine', value: 'Nectarine' }, + { id: 'orange', value: 'Orange' }, + { id: 'papaya', value: 'Papaya' }, + { id: 'passionfruit', value: 'Passionfruit' }, + { id: 'peach', value: 'Peach' }, + { id: 'pear', value: 'Pear' }, + { id: 'persimmon', value: 'Persimmon' }, + { id: 'pineapple', value: 'Pineapple' }, + { id: 'plum', value: 'Plum' }, + { id: 'pomegranate', value: 'Pomegranate' }, + { id: 'quince', value: 'Quince' }, + { id: 'rambutan', value: 'Rambutan' }, + { id: 'raspberry', value: 'Raspberry' }, + { id: 'soursop', value: 'Soursop' }, + { id: 'starfruit', value: 'Starfruit' }, + { id: 'strawberry', value: 'Strawberry' }, + { id: 'tangerine', value: 'Tangerine' }, + { id: 'watermelon', value: 'Watermelon' }, +]; diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx new file mode 100644 index 00000000000000..680df77b56c01a --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -0,0 +1,348 @@ +import type { Meta, StoryObj } from '@storybook/react-vite'; +import { useEffect, useState } from '@wordpress/element'; +import * as Combobox from '../index'; +import { ITEMS, type FixtureItem } from './fixtures'; + +const meta: Meta< typeof Combobox.Root > = { + title: 'Design System/Components/Form/Primitives/Combobox', + component: Combobox.Root, + subcomponents: { + Trigger: Combobox.Trigger, + Portal: Combobox.Portal, + Popup: Combobox.Popup, + Input: Combobox.Input, + List: Combobox.List, + ListBody: Combobox.ListBody, + ListFooter: Combobox.ListFooter, + Collection: Combobox.Collection, + Item: Combobox.Item, + Value: Combobox.Value, + Chips: Combobox.Chips, + ChipWithRemove: Combobox.ChipWithRemove, + Empty: Combobox.Empty, + Clear: Combobox.Clear, + }, +}; +export default meta; + +type Story = StoryObj< typeof Combobox.Root >; + +export const Default: Story = { + args: { + defaultValue: ITEMS[ 0 ], + items: ITEMS, + children: ( + <> + + +
+ +
+ No results found. + + + + { ( item: FixtureItem ) => ( + + { item.value } + + ) } + + + +
+ + ), + }, +}; + +/** + * For certain multiple select use cases, it may be better to design a custom + * selection state UI, rather than using a chip-based selection state UI like `SearchableChipSelect`. + * In such cases, the selector UI can be detached and inlined into a modal dialog, for example. + * + * To do this, omit the `Popup` and enable the `inline` prop on the `Root`. + */ +export const DetachedInline: Story = { + args: { + items: ITEMS, + multiple: true, + inline: true, + children: ( + <> + +
+ No results found. + + + { ( item: FixtureItem ) => ( + + { item.value } + + ) } + + +
+ + ), + }, +}; + +export const Creatable: Story = { + render: function Template( args ) { + const [ inputValue, setInputValue ] = useState( '' ); + const [ value, setValue ] = useState( ITEMS[ 0 ] ); + const hasNoExactMatch = + inputValue.length > 0 && + ! ITEMS.some( ( item ) => item.value === inputValue.trim() ); + const creatableItem = { + id: 'create', + value: + 'Create new item' + ( inputValue ? `: ${ inputValue }` : '' ), + }; + + return ( + { + const typedValue = newValue as FixtureItem; + if ( typedValue.id === 'create' ) { + // eslint-disable-next-line no-alert + alert( 'Show dialog to create new item!' ); + } else { + setValue( typedValue ); + } + args.onValueChange?.( newValue, event ); + } } + items={ + ! inputValue || hasNoExactMatch + ? [ ...ITEMS, creatableItem ] + : ITEMS + } + > + + +
+ +
+ No results found. + + + + { ( item: FixtureItem ) => + item.id !== creatableItem.id && ( + + { item.value } + + ) + } + + + + + { creatableItem.value } + + + +
+
+ ); + }, +}; + +export const AsyncItems: Story = { + render: function Template( args ) { + const LOADING_ITEM = { + id: 'loading', + value: 'Loading...', + }; + const [ items, setItems ] = useState( [ LOADING_ITEM ] ); + const [ value, setValue ] = useState< unknown >( LOADING_ITEM ); + + useEffect( () => { + const timeout = setTimeout( () => { + setItems( ITEMS ); + setValue( ITEMS[ 0 ] ); + }, 3000 ); + + return () => clearTimeout( timeout ); + }, [] ); + + return ( + + + +
+ +
+ No results found. + + + + { ( item: FixtureItem ) => ( + + { item.value } + + ) } + + + +
+
+ ); + }, +}; + +/** + * For custom needs, a `Combobox.Trigger` can take a custom render function as its children, + * while `Select.Item` can take arbitrary content as children. + * + * In this example, some extra information is added to each list item as an ARIA description. + */ +export const WithCustomTriggerAndItem: Story = { + args: { + items: ITEMS, + defaultValue: ITEMS[ 0 ], + children: ( + <> + + { ( item: FixtureItem ) => ( + + + { item.value } + + ) } + + +
+ +
+ + + + { ( item: FixtureItem ) => ( + +
+ { item.value } + +
+
+ ) } +
+
+
+
+ + ), + }, +}; + +/** + * Popovers in Gutenberg are managed with explicit z-index values, which can create + * situations where a popover renders below another popover, when you want it to be rendered above. + * + * The `--wp-ui-combobox-z-index` CSS variable controls the z-index of the + * `Combobox` positioner. Override it either: + * + * - **Globally**, by setting the variable on `:root` or `body` (raises every + * `Combobox` popup in the page), or + * - **Per instance**, by passing a `Combobox.Portal` with a `style` (or + * `className`) to `Combobox.Popup`'s `portal` prop. The variable cascades + * from the portal wrapper to everything rendered inside it. + * + * This story demonstrates the per-instance approach. + */ +export const WithCustomZIndex: Story = { + name: 'With Custom z-index', + args: { + defaultValue: ITEMS[ 0 ], + items: ITEMS, + children: ( + <> + + + } + > + + + + { ( item: FixtureItem ) => ( + + { item.value } + + ) } + + + + + + ), + }, +}; diff --git a/packages/ui/src/form/primitives/combobox/style.module.css b/packages/ui/src/form/primitives/combobox/style.module.css new file mode 100644 index 00000000000000..191b73f583a61b --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/style.module.css @@ -0,0 +1,72 @@ +@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides; + +@layer wp-ui-components { + .positioner { + z-index: var(--wp-ui-combobox-z-index, initial); + } + + .chip { + /* TODO: Use or create new control/interactive padding token */ + --wp-ui-combobox-chip-content-padding-inline-start: calc(2 * var(--wpds-dimension-base)); + + overflow: hidden; + display: flex; + align-items: center; + min-height: 24px; + border: 1px solid var(--wpds-color-stroke-interactive-neutral); + border-radius: 12px; + background-color: var(--wpds-color-bg-interactive-neutral-weak); + font-size: var(--wpds-typography-font-size-md); + color: var(--wpds-color-fg-interactive-neutral); + cursor: default; + + &:not([data-disabled]):has(button:not(:disabled, [aria-disabled="true"]):hover), + &:not([data-disabled]):focus { + background-color: var(--wpds-color-bg-interactive-neutral-weak-active); + border-color: var(--wpds-color-stroke-interactive-neutral-active); + outline: none; + color: var(--wpds-color-fg-interactive-neutral-active); + + @media ( forced-colors: active ) { + background-color: SelectedItem; + } + } + + &[data-disabled] { + background-color: var(--wpds-color-bg-interactive-neutral-weak-disabled); + border-color: var(--wpds-color-stroke-interactive-neutral-disabled); + color: var(--wpds-color-fg-interactive-neutral-disabled); + + @media ( forced-colors: active ) { + border-color: GrayText; + color: GrayText; + } + } + + &:has(.chip-prefix) { + /* TODO: Use or create new control/interactive padding token */ + --wp-ui-combobox-chip-content-padding-inline-start: var(--wpds-dimension-base); + } + } + + .chip-prefix { + display: flex; + justify-content: center; + align-items: center; + margin-inline-start: 1px; + width: 20px; + height: 20px; + border-radius: 50%; + overflow: hidden; + flex-shrink: 0; + } + + .chip-content { + padding-inline-start: var(--wp-ui-combobox-chip-content-padding-inline-start); + padding-block: var(--wpds-dimension-padding-xs); + } + + .chip-remove { + border: none; /* suppress border when in forced-colors mode */ + } +} diff --git a/packages/ui/src/form/primitives/combobox/test/index.test.tsx b/packages/ui/src/form/primitives/combobox/test/index.test.tsx new file mode 100644 index 00000000000000..7d50e8facf9fbd --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/test/index.test.tsx @@ -0,0 +1,307 @@ +import { render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { createRef } from '@wordpress/element'; +import * as Combobox from '../index'; + +const ITEMS = [ + { id: '1', value: 'Item 1' }, + { id: '2', value: 'Item 2' }, + { id: '3', value: 'Item 3' }, +]; + +type Item = ( typeof ITEMS )[ number ]; + +function renderDisabledMultiSelect() { + return render( + + items={ ITEMS } + multiple + disabled + defaultValue={ [ ITEMS[ 0 ] ] } + > + + + { ( value: Item[] ) => ( + <> + { value.map( ( item ) => ( + + { item.value } + + ) ) } + + + ) } + + + + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + + ); +} + +describe( 'Combobox', () => { + it( 'forwards ref', async () => { + const user = userEvent.setup(); + const triggerRef = createRef< HTMLButtonElement >(); + const popupRef = createRef< HTMLDivElement >(); + const inputRef = createRef< HTMLInputElement >(); + const listRef = createRef< HTMLDivElement >(); + const listBodyRef = createRef< HTMLDivElement >(); + const listFooterRef = createRef< HTMLDivElement >(); + const itemRef = createRef< HTMLDivElement >(); + const chipsRef = createRef< HTMLDivElement >(); + const chipWithRemoveRef = createRef< HTMLDivElement >(); + const clearRef = createRef< HTMLButtonElement >(); + const emptyRef = createRef< HTMLDivElement >(); + + render( + + + + + + + + + + + + No results found. + + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + + + ); + + // Test trigger ref before interaction + expect( triggerRef.current ).toBeInstanceOf( HTMLButtonElement ); + + // Click on the trigger to open the combobox popup + await user.click( triggerRef.current! ); + + // Now test that the popup and its child component refs are also available + await waitFor( () => { + expect( popupRef.current ).toBeInstanceOf( HTMLDivElement ); + } ); + expect( inputRef.current ).toBeInstanceOf( HTMLInputElement ); + expect( listRef.current ).toBeInstanceOf( HTMLDivElement ); + expect( listBodyRef.current ).toBeInstanceOf( HTMLDivElement ); + expect( listFooterRef.current ).toBeInstanceOf( HTMLDivElement ); + expect( itemRef.current ).toBeInstanceOf( HTMLDivElement ); + expect( chipsRef.current ).toBeInstanceOf( HTMLDivElement ); + expect( chipWithRemoveRef.current ).toBeInstanceOf( HTMLDivElement ); + expect( clearRef.current ).toBeInstanceOf( HTMLButtonElement ); + expect( emptyRef.current ).toBeInstanceOf( HTMLDivElement ); + } ); + + // The actual bug is a CSS grid overlap: both Empty and List target + // `grid-area: main`, so Empty rendered later in DOM stacks on top and + // blocks clicks. JSDOM doesn't compute CSS layout, so this test only + // verifies the behavioral contract, not the CSS fix itself. + it( 'allows selecting items when Empty is rendered after List', async () => { + const user = userEvent.setup(); + const onValueChange = jest.fn(); + + render( + + + + + + + + { ( item ) => ( + + { item.value } + + ) } + + + + No results found. + + + ); + + await user.click( screen.getByRole( 'combobox' ) ); + await waitFor( () => { + expect( screen.getByText( 'Item 2' ) ).toBeVisible(); + } ); + await user.click( screen.getByText( 'Item 2' ) ); + + expect( onValueChange ).toHaveBeenCalledWith( + ITEMS[ 1 ], + expect.anything() + ); + } ); + + describe( 'portal', () => { + it( 'should render inside the portal container when a custom target is provided', async () => { + const user = userEvent.setup(); + const containerRef = createRef< HTMLDivElement >(); + + render( +
+ + +
+ + } + > + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + +
+ ); + + await user.click( screen.getByRole( 'combobox' ) ); + + const item = await screen.findByRole( 'option', { + name: 'Item 1', + } ); + expect( item ).toBeVisible(); + + expect( screen.getByTestId( 'custom-container' ) ).toContainElement( + item + ); + } ); + + it( 'should render with a portal by default', async () => { + const user = userEvent.setup(); + + render( +
+ + + + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + +
+ ); + + await user.click( screen.getByRole( 'combobox' ) ); + + const item = await screen.findByRole( 'option', { + name: 'Item 1', + } ); + expect( item ).toBeVisible(); + + expect( screen.getByTestId( 'wrapper' ) ).not.toContainElement( + item + ); + } ); + } ); + + describe( 'when disabled', () => { + it( 'hides the chip remove button from screen readers', () => { + renderDisabledMultiSelect(); + + expect( + screen.queryByRole( 'button', { name: 'Remove' } ) + ).not.toBeInTheDocument(); + } ); + + it( 'hides the clear button from screen readers', () => { + renderDisabledMultiSelect(); + + expect( + screen.queryByRole( 'button', { name: 'Clear' } ) + ).not.toBeInTheDocument(); + } ); + + it( 'does not show a tooltip when the chip remove button is hovered', async () => { + const user = userEvent.setup( { pointerEventsCheck: 0 } ); + renderDisabledMultiSelect(); + + const removeButton = screen.getByLabelText( 'Remove', { + selector: 'button', + } ); + await user.hover( removeButton ); + + expect( screen.queryByRole( 'tooltip' ) ).not.toBeInTheDocument(); + } ); + + it( 'does not show a tooltip when the clear button is hovered', async () => { + const user = userEvent.setup( { pointerEventsCheck: 0 } ); + renderDisabledMultiSelect(); + + const clearButton = screen.getByLabelText( 'Clear', { + selector: 'button', + } ); + await user.hover( clearButton ); + + expect( screen.queryByRole( 'tooltip' ) ).not.toBeInTheDocument(); + } ); + } ); +} ); diff --git a/packages/ui/src/form/primitives/combobox/trigger.tsx b/packages/ui/src/form/primitives/combobox/trigger.tsx new file mode 100644 index 00000000000000..2a1b71aea01468 --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/trigger.tsx @@ -0,0 +1,56 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import clsx from 'clsx'; +import { forwardRef } from '@wordpress/element'; +import { chevronDown } from '@wordpress/icons'; +import { Icon } from '../../../icon'; +import focusStyles from '../../../utils/css/focus.module.css'; +import selectTriggerStyles from '../../../utils/css/select-trigger.module.css'; +import { InputLayout } from '../input-layout'; +import type { ComboboxTriggerProps } from './types'; + +const DEFAULT_RENDER = ( { + className, + children, + disabled, + ...restProps +}: Omit< ComboboxTriggerProps, 'children' > & { + children?: React.ReactNode; +} ) => ( + + + +); + +export const Trigger = forwardRef< HTMLButtonElement, ComboboxTriggerProps >( + function Trigger( + { children, render = DEFAULT_RENDER, ...restProps }, + ref + ) { + return ( + <_Combobox.Trigger ref={ ref } render={ render } { ...restProps }> + <_Combobox.Value>{ children } + + ); + } +); diff --git a/packages/ui/src/form/primitives/combobox/types.ts b/packages/ui/src/form/primitives/combobox/types.ts new file mode 100644 index 00000000000000..44f5c4ea2b1beb --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/types.ts @@ -0,0 +1,92 @@ +import type { Combobox as _Combobox } from '@base-ui/react/combobox'; +import type { ComponentPropsWithoutRef, ReactElement } from 'react'; + +import type { ComponentProps } from '../../../utils/types'; + +export type ComboboxChipsProps = ComponentProps< typeof _Combobox.Chips > & { + children?: React.ReactNode; +}; + +export type ComboboxChipWithRemoveProps = Omit< + ComponentProps< typeof _Combobox.Chip >, + 'prefix' +> & { + children?: React.ReactNode; + /** + * Circular element to render before the chip content. + */ + prefix?: React.ReactNode; +}; + +export type ComboboxClearProps = ComponentProps< typeof _Combobox.Clear > & { + children?: React.ReactNode; +}; + +export type ComboboxCollectionProps = _Combobox.Collection.Props; + +export type ComboboxEmptyProps = ComponentProps< typeof _Combobox.Empty > & { + children?: React.ReactNode; +}; + +export type ComboboxInputProps = Omit< + ComponentProps< typeof _Combobox.Input >, + 'size' +>; + +export type ComboboxItemProps = ComponentProps< typeof _Combobox.Item > & { + children?: React.ReactNode; + /** + * The variant of the item. + * + * - `'default'`: A standard item. + * - `'creatable'`: An item that triggers the creation of a new item. + * + * @default 'default' + */ + variant?: 'default' | 'creatable'; +}; + +export type ComboboxListProps = ComponentProps< typeof _Combobox.List > & { + children?: _Combobox.List.Props[ 'children' ]; +}; + +export type ComboboxListBodyProps = ComponentProps< 'div' > & { + children?: React.ReactNode; +}; + +export type ComboboxListFooterProps = ComponentProps< 'div' > & { + children?: React.ReactNode; +}; + +export type PortalProps = ComponentPropsWithoutRef< typeof _Combobox.Portal >; + +export type ComboboxPopupProps = ComponentProps< typeof _Combobox.Popup > & { + children?: React.ReactNode; + /** + * Optional portal element, typically `` with custom + * `container`. When omitted, `Combobox.Popup` uses `Combobox.Portal` with + * default props. Do not pass `children` on the portal element; they would be + * ignored. + */ + portal?: ReactElement< Omit< PortalProps, 'children' > >; +}; + +export type ComboboxRootProps< + Value, + Multiple extends boolean | undefined = false, +> = ComponentProps< typeof _Combobox.Root< Value, Multiple > > & { + children?: React.ReactNode; +}; + +export type ComboboxTriggerProps = ComponentProps< + typeof _Combobox.Trigger +> & { + children?: _Combobox.Value.Props[ 'children' ]; +}; + +export type ComboboxValueProps = { + /** + * Can be used to override the current value of the combobox. + */ + children?: _Combobox.Value.Props[ 'children' ]; +}; diff --git a/packages/ui/src/form/primitives/combobox/value.tsx b/packages/ui/src/form/primitives/combobox/value.tsx new file mode 100644 index 00000000000000..5b9df17af2114f --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/value.tsx @@ -0,0 +1,6 @@ +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import type { ComboboxValueProps } from './types'; + +export function Value( props: ComboboxValueProps ) { + return <_Combobox.Value { ...props } />; +} diff --git a/packages/ui/src/form/primitives/index.ts b/packages/ui/src/form/primitives/index.ts index b8cdf7d6eb8ed4..878c6a351d0e0c 100644 --- a/packages/ui/src/form/primitives/index.ts +++ b/packages/ui/src/form/primitives/index.ts @@ -1,4 +1,5 @@ export * as Autocomplete from './autocomplete'; +export * as Combobox from './combobox'; export * as Field from './field'; export * as Fieldset from './fieldset'; export { Input } from './input'; From 426e24a2fb0d2f4a539adc71069d555af3f101f8 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 May 2026 04:39:37 +0900 Subject: [PATCH 02/34] Fix popup slot --- packages/ui/src/form/primitives/combobox/popup.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/popup.tsx b/packages/ui/src/form/primitives/combobox/popup.tsx index 853ff393a686bd..715ba17afb8552 100644 --- a/packages/ui/src/form/primitives/combobox/popup.tsx +++ b/packages/ui/src/form/primitives/combobox/popup.tsx @@ -7,7 +7,7 @@ import { } from '@wordpress/theme'; import { unlock } from '../../../lock-unlock'; import { Portal } from './portal'; -import { renderPortalWithChildren } from '../../../utils/render-portal-with-children'; +import { renderSlotWithChildren } from '../../../utils/render-slot-with-children'; import itemPopupStyles from '../../../utils/css/item-popup.module.css'; import resetStyles from '../../../utils/css/resets.module.css'; import styles from './style.module.css'; @@ -37,6 +37,6 @@ export const Popup = forwardRef< HTMLDivElement, ComboboxPopupProps >( ); - return renderPortalWithChildren( portal, , portalChildren ); + return renderSlotWithChildren( portal, , portalChildren ); } ); From cc3f7a83e3f4fbacce60476e58fe56bb2192f84f Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 May 2026 05:48:42 +0900 Subject: [PATCH 03/34] Add `size` support --- .../ui/src/form/primitives/combobox/item.tsx | 9 ++- .../combobox/stories/index.story.tsx | 33 ++++++++++ .../src/form/primitives/combobox/trigger.tsx | 63 ++++++++----------- .../ui/src/form/primitives/combobox/types.ts | 15 +++++ 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/item.tsx b/packages/ui/src/form/primitives/combobox/item.tsx index 11f63605f184f7..25c8118acfe411 100644 --- a/packages/ui/src/form/primitives/combobox/item.tsx +++ b/packages/ui/src/form/primitives/combobox/item.tsx @@ -9,7 +9,13 @@ import type { ComboboxItemProps } from './types'; export const Item = forwardRef< HTMLDivElement, ComboboxItemProps >( function Item( - { className, children, variant = 'default', ...restProps }, + { + className, + children, + size = 'default', + variant = 'default', + ...restProps + }, ref ) { return ( @@ -17,6 +23,7 @@ export const Item = forwardRef< HTMLDivElement, ComboboxItemProps >( className={ clsx( resetStyles[ 'box-sizing' ], itemPopupStyles.item, + itemPopupStyles[ `is-size-${ size }` ], itemPopupStyles[ `is-${ variant }` ], className ) } diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 680df77b56c01a..988844f885a733 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -59,6 +59,39 @@ export const Default: Story = { }, }; +export const Compact: Story = { + args: { + defaultValue: ITEMS[ 0 ], + items: ITEMS, + children: ( + <> + + +
+ +
+ No results found. + + + + { ( item: FixtureItem ) => ( + + { item.value } + + ) } + + + +
+ + ), + }, +}; + /** * For certain multiple select use cases, it may be better to design a custom * selection state UI, rather than using a chip-based selection state UI like `SearchableChipSelect`. diff --git a/packages/ui/src/form/primitives/combobox/trigger.tsx b/packages/ui/src/form/primitives/combobox/trigger.tsx index 2a1b71aea01468..91076deee401b1 100644 --- a/packages/ui/src/form/primitives/combobox/trigger.tsx +++ b/packages/ui/src/form/primitives/combobox/trigger.tsx @@ -8,49 +8,36 @@ import selectTriggerStyles from '../../../utils/css/select-trigger.module.css'; import { InputLayout } from '../input-layout'; import type { ComboboxTriggerProps } from './types'; -const DEFAULT_RENDER = ( { - className, - children, - disabled, - ...restProps -}: Omit< ComboboxTriggerProps, 'children' > & { - children?: React.ReactNode; -} ) => ( - - - -); - export const Trigger = forwardRef< HTMLButtonElement, ComboboxTriggerProps >( function Trigger( - { children, render = DEFAULT_RENDER, ...restProps }, + { className, children, size = 'default', ...restProps }, ref ) { return ( - <_Combobox.Trigger ref={ ref } render={ render } { ...restProps }> - <_Combobox.Value>{ children } - + + <_Combobox.Trigger + { ...restProps } + className={ selectTriggerStyles.trigger } + data-can-disable-input-layout + ref={ ref } + > +
+ <_Combobox.Value>{ children } +
+ + +
); } ); diff --git a/packages/ui/src/form/primitives/combobox/types.ts b/packages/ui/src/form/primitives/combobox/types.ts index 44f5c4ea2b1beb..5c65f0f303c05e 100644 --- a/packages/ui/src/form/primitives/combobox/types.ts +++ b/packages/ui/src/form/primitives/combobox/types.ts @@ -2,6 +2,9 @@ import type { Combobox as _Combobox } from '@base-ui/react/combobox'; import type { ComponentPropsWithoutRef, ReactElement } from 'react'; import type { ComponentProps } from '../../../utils/types'; +import type { InputLayoutProps } from '../input-layout/types'; + +type ComboboxSize = Exclude< InputLayoutProps[ 'size' ], 'small' >; export type ComboboxChipsProps = ComponentProps< typeof _Combobox.Chips > & { children?: React.ReactNode; @@ -35,6 +38,12 @@ export type ComboboxInputProps = Omit< export type ComboboxItemProps = ComponentProps< typeof _Combobox.Item > & { children?: React.ReactNode; + /** + * The size of the item. + * + * @default 'default' + */ + size?: ComboboxSize; /** * The variant of the item. * @@ -82,6 +91,12 @@ export type ComboboxTriggerProps = ComponentProps< typeof _Combobox.Trigger > & { children?: _Combobox.Value.Props[ 'children' ]; + /** + * The size of the trigger. + * + * @default 'default' + */ + size?: ComboboxSize; }; export type ComboboxValueProps = { From 195e576421855cc324f51fa8d867ce426f726f0c Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 May 2026 05:51:38 +0900 Subject: [PATCH 04/34] Use padding tokens in stories --- .../primitives/combobox/stories/index.story.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 988844f885a733..80bcbd454f00c3 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -27,6 +27,11 @@ export default meta; type Story = StoryObj< typeof Combobox.Root >; +const inputWrapperStyle = { + padding: + 'var(--wpds-dimension-padding-sm) var(--wpds-dimension-padding-sm) var(--wpds-dimension-padding-xs)', +}; + export const Default: Story = { args: { defaultValue: ITEMS[ 0 ], @@ -35,7 +40,7 @@ export const Default: Story = { <> -
+
No results found. @@ -67,7 +72,7 @@ export const Compact: Story = { <> -
+
No results found. @@ -168,7 +173,7 @@ export const Creatable: Story = { > -
+
No results found. @@ -230,7 +235,7 @@ export const AsyncItems: Story = { > -
+
No results found. @@ -289,7 +294,7 @@ export const WithCustomTriggerAndItem: Story = { ) } -
+
From a511e330c6a78728e291ada45db6e5698bd0a472 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 May 2026 06:05:52 +0900 Subject: [PATCH 05/34] Move item popup typography styles --- packages/ui/src/utils/css/item-popup.module.css | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/utils/css/item-popup.module.css b/packages/ui/src/utils/css/item-popup.module.css index 234ab5e81c6c01..73d5319ee50b29 100644 --- a/packages/ui/src/utils/css/item-popup.module.css +++ b/packages/ui/src/utils/css/item-popup.module.css @@ -16,10 +16,6 @@ border: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral); box-shadow: var(--wpds-elevation-md); background-color: var(--wpds-color-bg-surface-neutral-strong); - font-family: var(--wpds-typography-font-family-body); - font-size: var(--wpds-typography-font-size-md); - line-height: 1.4; - color: var(--wpds-color-fg-interactive-neutral); } .list { @@ -27,6 +23,10 @@ grid-area: main; grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "scrollable" "footer"; + font-family: var(--wpds-typography-font-family-body); + font-size: var(--wpds-typography-font-size-md); + line-height: 1.4; + color: var(--wpds-color-fg-interactive-neutral); } .list-scrollable-container { @@ -124,6 +124,9 @@ align-items: center; min-height: var(--wp-ui-popup-empty-min-height); padding-inline: var(--wp-ui-popup-empty-padding-inline); + font-family: var(--wpds-typography-font-family-body); + font-size: var(--wpds-typography-font-size-md); + line-height: 1.4; color: var(--wpds-color-fg-content-neutral-weak); } From 6885f67b1cd6c0f7779b8119cd564948b055da4c Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 May 2026 06:07:12 +0900 Subject: [PATCH 06/34] Use line height token --- packages/ui/src/utils/css/item-popup.module.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/utils/css/item-popup.module.css b/packages/ui/src/utils/css/item-popup.module.css index 73d5319ee50b29..7b966d45ab4e37 100644 --- a/packages/ui/src/utils/css/item-popup.module.css +++ b/packages/ui/src/utils/css/item-popup.module.css @@ -25,7 +25,7 @@ grid-template-areas: "scrollable" "footer"; font-family: var(--wpds-typography-font-family-body); font-size: var(--wpds-typography-font-size-md); - line-height: 1.4; + line-height: var(--wpds-typography-line-height-sm); color: var(--wpds-color-fg-interactive-neutral); } @@ -126,7 +126,7 @@ padding-inline: var(--wp-ui-popup-empty-padding-inline); font-family: var(--wpds-typography-font-family-body); font-size: var(--wpds-typography-font-size-md); - line-height: 1.4; + line-height: var(--wpds-typography-line-height-sm); color: var(--wpds-color-fg-content-neutral-weak); } From 48e0c01c9f59b33e14523278b3904778174c589b Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 May 2026 06:11:51 +0900 Subject: [PATCH 07/34] Fix chip component name --- .../ui/src/form/primitives/combobox/chip-with-remove.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx index f96f772d607fe9..36d2016d5528dd 100644 --- a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx +++ b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx @@ -17,7 +17,10 @@ import styles from './style.module.css'; export const ChipWithRemove = forwardRef< HTMLDivElement, ComboboxChipWithRemoveProps ->( function Clear( { className, children, prefix, ...restProps }, ref ) { +>( function ChipWithRemove( + { className, children, prefix, ...restProps }, + ref +) { return ( <_Combobox.Chip ref={ ref } From 8349f059fc8b82bb5156d6bbe2dc797defc326bc Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Mon, 18 May 2026 22:39:27 +0900 Subject: [PATCH 08/34] Fix chip docs --- packages/ui/src/form/primitives/combobox/chip-with-remove.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx index 36d2016d5528dd..a550009ae8de6a 100644 --- a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx +++ b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx @@ -10,9 +10,6 @@ import styles from './style.module.css'; /** * A utility component that combines a chip and a remove button, * with standard styling. - * - * For custom designs, use the `Combobox.Chip` and `Combobox.ChipRemove` - * components directly. */ export const ChipWithRemove = forwardRef< HTMLDivElement, From d1973cb02c6e91648da83659db5ba507ca57f2eb Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Mon, 18 May 2026 22:43:18 +0900 Subject: [PATCH 09/34] Fix combobox story copy --- .../ui/src/form/primitives/combobox/stories/index.story.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 80bcbd454f00c3..696d61038d6310 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -262,7 +262,7 @@ export const AsyncItems: Story = { /** * For custom needs, a `Combobox.Trigger` can take a custom render function as its children, - * while `Select.Item` can take arbitrary content as children. + * while `Combobox.Item` can take arbitrary content as children. * * In this example, some extra information is added to each list item as an ARIA description. */ @@ -360,7 +360,7 @@ export const WithCustomZIndex: Story = { portal={ } From 9a74c902df608055a9e2c9d1d89c9f6f935d5e06 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Mon, 18 May 2026 22:49:00 +0900 Subject: [PATCH 10/34] Add changelog --- packages/ui/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md index 67152620600551..bb7f10e811531e 100644 --- a/packages/ui/CHANGELOG.md +++ b/packages/ui/CHANGELOG.md @@ -7,6 +7,7 @@ - `Card`: `Card.FullBleed` now supports edge-bumping in additional positions ([#77856](https://github.com/WordPress/gutenberg/pull/77856)): - As the **first child of `Card.Header`**, it extends flush to the card's top and side edges — ideal for hero images. Inter-sibling spacing is consumer-managed: compose `Card.Header` with `Stack` via the `render` prop to add a gap between the hero and following siblings (e.g. `Card.Title`). - As the **sole child of `Card.Content`**, it extends flush to the card's side edges and additionally to the top edge when `Content` is the first card child, or the bottom edge when it is the last. This enables full-bleed content panels with or without a header above them. +- Add `Combobox` primitive ([#78399](https://github.com/WordPress/gutenberg/pull/78399)). ### Enhancements From 1c7e8abbe47ff8f7e90cc4970f67f8b1fd4bc76c Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Mon, 18 May 2026 23:04:26 +0900 Subject: [PATCH 11/34] Add combobox compat overlay slot --- .../src/form/primitives/combobox/portal.tsx | 12 +- .../primitives/combobox/test/index.test.tsx | 145 ++++++++++++++++++ .../wp-compat-overlay-slot.story.jsx | 84 +++++++++- 3 files changed, 232 insertions(+), 9 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/portal.tsx b/packages/ui/src/form/primitives/combobox/portal.tsx index 05d509fa18ee60..374f6a24a558c2 100644 --- a/packages/ui/src/form/primitives/combobox/portal.tsx +++ b/packages/ui/src/form/primitives/combobox/portal.tsx @@ -1,15 +1,23 @@ import { Combobox as _Combobox } from '@base-ui/react/combobox'; import { forwardRef } from '@wordpress/element'; import type { PortalProps } from './types'; +import { getWpCompatOverlaySlot } from '../../../utils/wp-compat-overlay-slot'; /** * Root element that portals `Combobox` popup content. Pass to * `Combobox.Popup`'s `portal` prop. When `portal` is omitted, * `Combobox.Popup` uses this component with default props. + * `container` defaults to the `@wordpress/ui` compat overlay slot. */ const Portal = forwardRef< HTMLDivElement, PortalProps >( - function ComboboxPortal( props, ref ) { - return <_Combobox.Portal ref={ ref } { ...props } />; + function ComboboxPortal( { container, ...restProps }, ref ) { + return ( + <_Combobox.Portal + container={ container ?? getWpCompatOverlaySlot() } + { ...restProps } + ref={ ref } + /> + ); } ); diff --git a/packages/ui/src/form/primitives/combobox/test/index.test.tsx b/packages/ui/src/form/primitives/combobox/test/index.test.tsx index 7d50e8facf9fbd..f568c36bc438c5 100644 --- a/packages/ui/src/form/primitives/combobox/test/index.test.tsx +++ b/packages/ui/src/form/primitives/combobox/test/index.test.tsx @@ -1,7 +1,9 @@ import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { createRef } from '@wordpress/element'; +import type { ReactNode } from 'react'; import * as Combobox from '../index'; +import { useEnableWpCompatOverlaySlot } from '../../../../utils/use-enable-wp-compat-overlay-slot'; const ITEMS = [ { id: '1', value: 'Item 1' }, @@ -263,6 +265,149 @@ describe( 'Combobox', () => { } ); } ); + // Slot is identified by a data attribute, not a user-facing role/text. + /* eslint-disable testing-library/no-node-access */ + describe( 'wp compat overlay slot', () => { + const SLOT_SELECTOR = '[data-wp-compat-overlay-slot]'; + + // Exercises the public opt-in path rather than poking the flag. + function WithSlotEnabled( { children }: { children: ReactNode } ) { + useEnableWpCompatOverlaySlot(); + return <>{ children }; + } + + afterEach( () => { + // The hook is one-way at runtime; reset explicitly between tests. + delete ( window as { __wpUiCompatOverlaySlotEnabled?: boolean } ) + .__wpUiCompatOverlaySlotEnabled; + document + .querySelectorAll( SLOT_SELECTOR ) + .forEach( ( el ) => el.remove() ); + } ); + + it( 'portals the popup into the slot when the consumer opts in', async () => { + const user = userEvent.setup(); + + render( + + + + + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + + + ); + + await user.click( screen.getByRole( 'combobox' ) ); + + const item = await screen.findByRole( 'option', { + name: 'Item 1', + } ); + expect( item ).toBeVisible(); + + const slot = document.querySelector( SLOT_SELECTOR ); + expect( slot ).not.toBeNull(); + expect( slot ).toContainElement( item ); + } ); + + it( 'does not create a slot when the consumer has not opted in (dormant default)', async () => { + const user = userEvent.setup(); + + render( + + + + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + + ); + + await user.click( screen.getByRole( 'combobox' ) ); + + const item = await screen.findByRole( 'option', { + name: 'Item 1', + } ); + expect( item ).toBeVisible(); + + expect( document.querySelector( SLOT_SELECTOR ) ).toBeNull(); + } ); + + it( 'lets a caller-supplied portal container override the slot', async () => { + const user = userEvent.setup(); + const containerRef = createRef< HTMLDivElement >(); + + render( + + + +
+ + } + > + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + + + ); + + await user.click( screen.getByRole( 'combobox' ) ); + + const item = await screen.findByRole( 'option', { + name: 'Item 1', + } ); + expect( item ).toBeVisible(); + expect( screen.getByTestId( 'custom-container' ) ).toContainElement( + item + ); + } ); + } ); + /* eslint-enable testing-library/no-node-access */ + describe( 'when disabled', () => { it( 'hides the chip remove button from screen readers', () => { renderDisabledMultiSelect(); diff --git a/storybook/stories/playground/wp-compat-overlay-slot.story.jsx b/storybook/stories/playground/wp-compat-overlay-slot.story.jsx index 3624d6a170396a..479e6904606bdf 100644 --- a/storybook/stories/playground/wp-compat-overlay-slot.story.jsx +++ b/storybook/stories/playground/wp-compat-overlay-slot.story.jsx @@ -3,14 +3,17 @@ */ import { Modal, Popover, Button } from '@wordpress/components'; import { useState } from '@wordpress/element'; +import { + Autocomplete, + Combobox, + Select, + SelectControl, + Tooltip, +} from '@wordpress/ui'; /** * Internal dependencies */ -import * as Tooltip from '../../../packages/ui/src/tooltip'; -import * as Select from '../../../packages/ui/src/form/primitives/select'; -import { SelectControl } from '../../../packages/ui/src/form/select-control'; -import * as Autocomplete from '../../../packages/ui/src/form/primitives/autocomplete'; import { WithWpCompatOverlaySlot } from './with-wp-compat-overlay-slot'; const selectItems = [ @@ -25,10 +28,15 @@ const autocompleteItems = [ { id: '3', value: 'Item 3' }, ]; +const inputWrapperStyle = { + padding: + 'var(--wpds-dimension-padding-sm) var(--wpds-dimension-padding-sm) var(--wpds-dimension-padding-xs)', +}; + // Cross-library stacking: `@wordpress/ui` overlays (`Tooltip`, `Select`, -// `SelectControl`, `Autocomplete`) inside a `@wordpress/components` -// Modal / Popover should sit above the components-side overlay via the -// compat overlay slot. +// `Combobox`, `SelectControl`, `Autocomplete`) inside a +// `@wordpress/components` Modal / Popover should sit above the +// components-side overlay via the compat overlay slot. export default { title: 'Playground/Debug fixtures/WP Compat Overlay Slot', decorators: [ WithWpCompatOverlaySlot ], @@ -79,6 +87,37 @@ export const InsideComponentsModal = {
+
+ + + +
+ +
+ + No results found. + + + + + { ( item ) => ( + + { item.label } + + ) } + + + +
+
+
+
+
+ + + +
+ +
+ + No results found. + + + + + { ( item ) => ( + + { item.label } + + ) } + + + +
+
+
+
Date: Mon, 18 May 2026 23:27:43 +0900 Subject: [PATCH 12/34] Remove item popup typography changes --- packages/ui/src/utils/css/item-popup.module.css | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/ui/src/utils/css/item-popup.module.css b/packages/ui/src/utils/css/item-popup.module.css index 7b966d45ab4e37..234ab5e81c6c01 100644 --- a/packages/ui/src/utils/css/item-popup.module.css +++ b/packages/ui/src/utils/css/item-popup.module.css @@ -16,6 +16,10 @@ border: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral); box-shadow: var(--wpds-elevation-md); background-color: var(--wpds-color-bg-surface-neutral-strong); + font-family: var(--wpds-typography-font-family-body); + font-size: var(--wpds-typography-font-size-md); + line-height: 1.4; + color: var(--wpds-color-fg-interactive-neutral); } .list { @@ -23,10 +27,6 @@ grid-area: main; grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "scrollable" "footer"; - font-family: var(--wpds-typography-font-family-body); - font-size: var(--wpds-typography-font-size-md); - line-height: var(--wpds-typography-line-height-sm); - color: var(--wpds-color-fg-interactive-neutral); } .list-scrollable-container { @@ -124,9 +124,6 @@ align-items: center; min-height: var(--wp-ui-popup-empty-min-height); padding-inline: var(--wp-ui-popup-empty-padding-inline); - font-family: var(--wpds-typography-font-family-body); - font-size: var(--wpds-typography-font-size-md); - line-height: var(--wpds-typography-line-height-sm); color: var(--wpds-color-fg-content-neutral-weak); } From 7fbfa05ef60423d23d595936266256c1a6abae29 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Mon, 18 May 2026 23:48:08 +0900 Subject: [PATCH 13/34] Clean up --- .../stories/playground/wp-compat-overlay-slot.story.jsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/storybook/stories/playground/wp-compat-overlay-slot.story.jsx b/storybook/stories/playground/wp-compat-overlay-slot.story.jsx index 479e6904606bdf..a11e124d297a81 100644 --- a/storybook/stories/playground/wp-compat-overlay-slot.story.jsx +++ b/storybook/stories/playground/wp-compat-overlay-slot.story.jsx @@ -1,6 +1,3 @@ -/** - * WordPress dependencies - */ import { Modal, Popover, Button } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { @@ -11,9 +8,6 @@ import { Tooltip, } from '@wordpress/ui'; -/** - * Internal dependencies - */ import { WithWpCompatOverlaySlot } from './with-wp-compat-overlay-slot'; const selectItems = [ From c8345c3de3b7d057d291d512f2f3f4a8fbaab98c Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 19 May 2026 01:20:46 +0900 Subject: [PATCH 14/34] Add support for custom label in remove chip button --- .../primitives/combobox/chip-with-remove.tsx | 4 +-- .../primitives/combobox/test/index.test.tsx | 31 +++++++++++++++++++ .../ui/src/form/primitives/combobox/types.ts | 6 ++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx index a550009ae8de6a..fb5f2fed2b6f08 100644 --- a/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx +++ b/packages/ui/src/form/primitives/combobox/chip-with-remove.tsx @@ -15,7 +15,7 @@ export const ChipWithRemove = forwardRef< HTMLDivElement, ComboboxChipWithRemoveProps >( function ChipWithRemove( - { className, children, prefix, ...restProps }, + { className, children, prefix, removeLabel = __( 'Remove' ), ...restProps }, ref ) { return ( @@ -34,7 +34,7 @@ export const ChipWithRemove = forwardRef< render={ ( props, { disabled } ) => ( { expect( emptyRef.current ).toBeInstanceOf( HTMLDivElement ); } ); + it( 'uses a custom accessible label for chip remove buttons', () => { + render( + + items={ ITEMS } + multiple + defaultValue={ [ ITEMS[ 0 ] ] } + > + + + { ( value: Item[] ) => ( + <> + { value.map( ( item ) => ( + + { item.value } + + ) ) } + + ) } + + + + ); + + expect( + screen.getByRole( 'button', { name: 'Remove Item 1' } ) + ).toBeVisible(); + } ); + // The actual bug is a CSS grid overlap: both Empty and List target // `grid-area: main`, so Empty rendered later in DOM stacks on top and // blocks clicks. JSDOM doesn't compute CSS layout, so this test only diff --git a/packages/ui/src/form/primitives/combobox/types.ts b/packages/ui/src/form/primitives/combobox/types.ts index 5c65f0f303c05e..680e598455e288 100644 --- a/packages/ui/src/form/primitives/combobox/types.ts +++ b/packages/ui/src/form/primitives/combobox/types.ts @@ -19,6 +19,12 @@ export type ComboboxChipWithRemoveProps = Omit< * Circular element to render before the chip content. */ prefix?: React.ReactNode; + /** + * Accessible label for the remove button. + * + * @default __( 'Remove' ) + */ + removeLabel?: string; }; export type ComboboxClearProps = ComponentProps< typeof _Combobox.Clear > & { From 2adacc3ca5fb5c69ef97e9a8a783cf5d8586d66d Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 19 May 2026 01:32:50 +0900 Subject: [PATCH 15/34] Add Combobox positioner --- .../ui/src/form/primitives/combobox/index.ts | 1 + .../ui/src/form/primitives/combobox/popup.tsx | 38 +++++++-------- .../form/primitives/combobox/positioner.tsx | 29 ++++++++++++ .../combobox/stories/index.story.tsx | 10 ++-- .../primitives/combobox/test/index.test.tsx | 46 ++++++++++++++++++- .../ui/src/form/primitives/combobox/types.ts | 10 ++++ 6 files changed, 107 insertions(+), 27 deletions(-) create mode 100644 packages/ui/src/form/primitives/combobox/positioner.tsx diff --git a/packages/ui/src/form/primitives/combobox/index.ts b/packages/ui/src/form/primitives/combobox/index.ts index 53c9468b239825..a4cc8e604589dc 100644 --- a/packages/ui/src/form/primitives/combobox/index.ts +++ b/packages/ui/src/form/primitives/combobox/index.ts @@ -9,6 +9,7 @@ export { List } from './list'; export { ListBody } from './list-body'; export { ListFooter } from './list-footer'; export { Portal } from './portal'; +export { Positioner } from './positioner'; export { Popup } from './popup'; export { Root } from './root'; export { Trigger } from './trigger'; diff --git a/packages/ui/src/form/primitives/combobox/popup.tsx b/packages/ui/src/form/primitives/combobox/popup.tsx index 715ba17afb8552..6da83929dfde02 100644 --- a/packages/ui/src/form/primitives/combobox/popup.tsx +++ b/packages/ui/src/form/primitives/combobox/popup.tsx @@ -7,36 +7,32 @@ import { } from '@wordpress/theme'; import { unlock } from '../../../lock-unlock'; import { Portal } from './portal'; +import { Positioner } from './positioner'; import { renderSlotWithChildren } from '../../../utils/render-slot-with-children'; import itemPopupStyles from '../../../utils/css/item-popup.module.css'; -import resetStyles from '../../../utils/css/resets.module.css'; -import styles from './style.module.css'; import type { ComboboxPopupProps } from './types'; -import { ITEM_POPUP_POSITIONER_PROPS } from '../constants'; const ThemeProvider: typeof ThemeProviderType = unlock( themePrivateApis ).ThemeProvider; export const Popup = forwardRef< HTMLDivElement, ComboboxPopupProps >( - function Popup( { className, portal, ...restProps }, ref ) { - const portalChildren = ( - <_Combobox.Positioner - { ...ITEM_POPUP_POSITIONER_PROPS } - className={ clsx( - resetStyles[ 'box-sizing' ], - styles.positioner - ) } - > - - <_Combobox.Popup - ref={ ref } - className={ clsx( itemPopupStyles.popup, className ) } - { ...restProps } - /> - - + function Popup( { className, portal, positioner, ...restProps }, ref ) { + const popupContent = ( + + <_Combobox.Popup + ref={ ref } + className={ clsx( itemPopupStyles.popup, className ) } + { ...restProps } + /> + ); - return renderSlotWithChildren( portal, , portalChildren ); + const positionedPopup = renderSlotWithChildren( + positioner, + , + popupContent + ); + + return renderSlotWithChildren( portal, , positionedPopup ); } ); diff --git a/packages/ui/src/form/primitives/combobox/positioner.tsx b/packages/ui/src/form/primitives/combobox/positioner.tsx new file mode 100644 index 00000000000000..67f50f175029cc --- /dev/null +++ b/packages/ui/src/form/primitives/combobox/positioner.tsx @@ -0,0 +1,29 @@ +import clsx from 'clsx'; +import { Combobox as _Combobox } from '@base-ui/react/combobox'; +import { forwardRef } from '@wordpress/element'; +import type { PositionerProps } from './types'; +import resetStyles from '../../../utils/css/resets.module.css'; +import styles from './style.module.css'; +import { ITEM_POPUP_POSITIONER_PROPS } from '../constants'; + +/** + * Used to apply custom positioning to `Combobox`'s popup content. + */ +const Positioner = forwardRef< HTMLDivElement, PositionerProps >( + function ComboboxPositioner( { className, ...props }, ref ) { + return ( + <_Combobox.Positioner + { ...ITEM_POPUP_POSITIONER_PROPS } + { ...props } + ref={ ref } + className={ clsx( + resetStyles[ 'box-sizing' ], + styles.positioner, + className + ) } + /> + ); + } +); + +export { Positioner }; diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 696d61038d6310..8d0e02fb3b20a3 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -9,6 +9,7 @@ const meta: Meta< typeof Combobox.Root > = { subcomponents: { Trigger: Combobox.Trigger, Portal: Combobox.Portal, + Positioner: Combobox.Positioner, Popup: Combobox.Popup, Input: Combobox.Input, List: Combobox.List, @@ -342,9 +343,8 @@ export const WithCustomTriggerAndItem: Story = { * * - **Globally**, by setting the variable on `:root` or `body` (raises every * `Combobox` popup in the page), or - * - **Per instance**, by passing a `Combobox.Portal` with a `style` (or - * `className`) to `Combobox.Popup`'s `portal` prop. The variable cascades - * from the portal wrapper to everything rendered inside it. + * - **Per instance**, by passing a `Combobox.Positioner` with a `style` (or + * `className`) to `Combobox.Popup`'s `positioner` prop. * * This story demonstrates the per-instance approach. */ @@ -357,8 +357,8 @@ export const WithCustomZIndex: Story = { <> { const user = userEvent.setup(); const triggerRef = createRef< HTMLButtonElement >(); const popupRef = createRef< HTMLDivElement >(); + const positionerRef = createRef< HTMLDivElement >(); const inputRef = createRef< HTMLInputElement >(); const listRef = createRef< HTMLDivElement >(); const listBodyRef = createRef< HTMLDivElement >(); @@ -70,7 +71,10 @@ describe( 'Combobox', () => { render( - + } + > @@ -117,6 +121,7 @@ describe( 'Combobox', () => { await waitFor( () => { expect( popupRef.current ).toBeInstanceOf( HTMLDivElement ); } ); + expect( positionerRef.current ).toBeInstanceOf( HTMLDivElement ); expect( inputRef.current ).toBeInstanceOf( HTMLInputElement ); expect( listRef.current ).toBeInstanceOf( HTMLDivElement ); expect( listBodyRef.current ).toBeInstanceOf( HTMLDivElement ); @@ -128,6 +133,45 @@ describe( 'Combobox', () => { expect( emptyRef.current ).toBeInstanceOf( HTMLDivElement ); } ); + it( 'uses a custom positioner', async () => { + const user = userEvent.setup(); + + render( + + + + } + > + + + + { ( item ) => ( + + { item.value } + + ) } + + + + + + ); + + await user.click( screen.getByRole( 'combobox' ) ); + + const item = await screen.findByRole( 'option', { + name: 'Item 1', + } ); + expect( screen.getByTestId( 'custom-positioner' ) ).toContainElement( + item + ); + } ); + it( 'uses a custom accessible label for chip remove buttons', () => { render( diff --git a/packages/ui/src/form/primitives/combobox/types.ts b/packages/ui/src/form/primitives/combobox/types.ts index 680e598455e288..2eac745e3f9959 100644 --- a/packages/ui/src/form/primitives/combobox/types.ts +++ b/packages/ui/src/form/primitives/combobox/types.ts @@ -75,6 +75,8 @@ export type ComboboxListFooterProps = ComponentProps< 'div' > & { export type PortalProps = ComponentPropsWithoutRef< typeof _Combobox.Portal >; +export type PositionerProps = ComponentProps< typeof _Combobox.Positioner >; + export type ComboboxPopupProps = ComponentProps< typeof _Combobox.Popup > & { children?: React.ReactNode; /** @@ -84,6 +86,14 @@ export type ComboboxPopupProps = ComponentProps< typeof _Combobox.Popup > & { * ignored. */ portal?: ReactElement< Omit< PortalProps, 'children' > >; + /** + * Optional positioner element, typically `` with + * custom positioning props (`side`, `align`, `sideOffset`, collision + * settings, etc.). When omitted, `Combobox.Popup` uses + * `Combobox.Positioner` with default props. Do not pass `children` on the + * positioner element; they would be ignored. + */ + positioner?: ReactElement< Omit< PositionerProps, 'children' > >; }; export type ComboboxRootProps< From 1837f4954d135a48bb892cfc3c667369f71f7a88 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 19 May 2026 01:52:01 +0900 Subject: [PATCH 16/34] Add Combobox value placeholder support --- .../src/form/primitives/combobox/test/index.test.tsx | 10 ++++++++++ packages/ui/src/form/primitives/combobox/types.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/form/primitives/combobox/test/index.test.tsx b/packages/ui/src/form/primitives/combobox/test/index.test.tsx index 502be6d2640086..5ec5eafff6a6a6 100644 --- a/packages/ui/src/form/primitives/combobox/test/index.test.tsx +++ b/packages/ui/src/form/primitives/combobox/test/index.test.tsx @@ -203,6 +203,16 @@ describe( 'Combobox', () => { ).toBeVisible(); } ); + it( 'supports a value placeholder', () => { + render( + + + + ); + + expect( screen.getByText( 'No item selected' ) ).toBeVisible(); + } ); + // The actual bug is a CSS grid overlap: both Empty and List target // `grid-area: main`, so Empty rendered later in DOM stacks on top and // blocks clicks. JSDOM doesn't compute CSS layout, so this test only diff --git a/packages/ui/src/form/primitives/combobox/types.ts b/packages/ui/src/form/primitives/combobox/types.ts index 2eac745e3f9959..21b015d4298db6 100644 --- a/packages/ui/src/form/primitives/combobox/types.ts +++ b/packages/ui/src/form/primitives/combobox/types.ts @@ -115,7 +115,7 @@ export type ComboboxTriggerProps = ComponentProps< size?: ComboboxSize; }; -export type ComboboxValueProps = { +export type ComboboxValueProps = ComponentProps< typeof _Combobox.Value > & { /** * Can be used to override the current value of the combobox. */ From 373b06827457239f1b3c43512d5a63d61e002886 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 19 May 2026 01:57:15 +0900 Subject: [PATCH 17/34] Add Combobox Storybook status --- .../src/form/primitives/combobox/stories/index.story.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 8d0e02fb3b20a3..57b20b6cca9b74 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -23,6 +23,13 @@ const meta: Meta< typeof Combobox.Root > = { Empty: Combobox.Empty, Clear: Combobox.Clear, }, + parameters: { + componentStatus: { + status: 'use-with-caution', + whereUsed: 'global', + notes: 'Not yet recommended for use alongside components from `@wordpress/components`, pending review of style consistency with `@wordpress/components`, overlays compatibility, and component set completeness. See [WordPress/gutenberg#76135](https://github.com/WordPress/gutenberg/issues/76135).', + }, + }, }; export default meta; From 4451d4f6569d2383048938380e4787905fbc478e Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 19 May 2026 02:55:53 +0900 Subject: [PATCH 18/34] Add placeholder support to Trigger --- .../combobox/stories/index.story.tsx | 1 - .../primitives/combobox/test/index.test.tsx | 26 +++++++++++++++++++ .../src/form/primitives/combobox/trigger.tsx | 13 ++++++++-- .../ui/src/form/primitives/combobox/types.ts | 7 +++++ .../src/utils/css/select-trigger.module.css | 2 +- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 57b20b6cca9b74..349624ba864bdf 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -42,7 +42,6 @@ const inputWrapperStyle = { export const Default: Story = { args: { - defaultValue: ITEMS[ 0 ], items: ITEMS, children: ( <> diff --git a/packages/ui/src/form/primitives/combobox/test/index.test.tsx b/packages/ui/src/form/primitives/combobox/test/index.test.tsx index 5ec5eafff6a6a6..60f3004941bbc8 100644 --- a/packages/ui/src/form/primitives/combobox/test/index.test.tsx +++ b/packages/ui/src/form/primitives/combobox/test/index.test.tsx @@ -213,6 +213,32 @@ describe( 'Combobox', () => { expect( screen.getByText( 'No item selected' ) ).toBeVisible(); } ); + it( 'renders a default trigger placeholder when no value is selected', () => { + render( + + + + ); + + const trigger = screen.getByRole( 'combobox' ); + + expect( trigger ).toHaveTextContent( 'Select' ); + expect( trigger ).toHaveAttribute( 'data-placeholder' ); + } ); + + it( 'supports custom trigger placeholder text', () => { + render( + + + + ); + + const trigger = screen.getByRole( 'combobox' ); + + expect( trigger ).toHaveTextContent( 'Choose an item' ); + expect( trigger ).toHaveAttribute( 'data-placeholder' ); + } ); + // The actual bug is a CSS grid overlap: both Empty and List target // `grid-area: main`, so Empty rendered later in DOM stacks on top and // blocks clicks. JSDOM doesn't compute CSS layout, so this test only diff --git a/packages/ui/src/form/primitives/combobox/trigger.tsx b/packages/ui/src/form/primitives/combobox/trigger.tsx index 91076deee401b1..95e1d25189ae0b 100644 --- a/packages/ui/src/form/primitives/combobox/trigger.tsx +++ b/packages/ui/src/form/primitives/combobox/trigger.tsx @@ -1,6 +1,7 @@ import { Combobox as _Combobox } from '@base-ui/react/combobox'; import clsx from 'clsx'; import { forwardRef } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; import { chevronDown } from '@wordpress/icons'; import { Icon } from '../../../icon'; import focusStyles from '../../../utils/css/focus.module.css'; @@ -10,7 +11,13 @@ import type { ComboboxTriggerProps } from './types'; export const Trigger = forwardRef< HTMLButtonElement, ComboboxTriggerProps >( function Trigger( - { className, children, size = 'default', ...restProps }, + { + className, + children, + size = 'default', + placeholder = __( 'Select' ), + ...restProps + }, ref ) { return ( @@ -29,7 +36,9 @@ export const Trigger = forwardRef< HTMLButtonElement, ComboboxTriggerProps >( ref={ ref } >
- <_Combobox.Value>{ children } + <_Combobox.Value placeholder={ placeholder }> + { children } +
& { children?: _Combobox.Value.Props[ 'children' ]; + /** + * Text to show when no value is selected. + * This is overridden by `children` if specified, or by a null item's label in `items`. + * + * @default __( 'Select' ) + */ + placeholder?: _Combobox.Value.Props[ 'placeholder' ]; /** * The size of the trigger. * diff --git a/packages/ui/src/utils/css/select-trigger.module.css b/packages/ui/src/utils/css/select-trigger.module.css index b0e3271deb2fdd..f137eb326099f4 100644 --- a/packages/ui/src/utils/css/select-trigger.module.css +++ b/packages/ui/src/utils/css/select-trigger.module.css @@ -51,7 +51,7 @@ text-overflow: ellipsis; white-space: nowrap; - &[data-placeholder] { + .trigger[data-placeholder] & { color: var(--wpds-color-fg-interactive-neutral-disabled); } } From 962247685dc3ed240a28dd57fee3321995585175 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 19 May 2026 04:04:26 +0900 Subject: [PATCH 19/34] Update Combobox story item shape --- .../primitives/combobox/stories/fixtures.ts | 102 +++++++++--------- .../combobox/stories/index.story.tsx | 59 +++++----- 2 files changed, 82 insertions(+), 79 deletions(-) diff --git a/packages/ui/src/form/primitives/combobox/stories/fixtures.ts b/packages/ui/src/form/primitives/combobox/stories/fixtures.ts index 88625e26db6040..e1fffaba9bc5a9 100644 --- a/packages/ui/src/form/primitives/combobox/stories/fixtures.ts +++ b/packages/ui/src/form/primitives/combobox/stories/fixtures.ts @@ -1,57 +1,57 @@ export interface FixtureItem { - id: string; value: string; + label: string; } export const ITEMS: FixtureItem[] = [ - { id: 'apple', value: 'Apple' }, - { id: 'apricot', value: 'Apricot' }, - { id: 'banana', value: 'Banana' }, - { id: 'blackberry', value: 'Blackberry' }, - { id: 'blueberry', value: 'Blueberry' }, - { id: 'boysenberry', value: 'Boysenberry' }, - { id: 'breadfruit', value: 'Breadfruit' }, - { id: 'cantaloupe', value: 'Cantaloupe' }, - { id: 'cherry', value: 'Cherry' }, - { id: 'clementine', value: 'Clementine' }, - { id: 'coconut', value: 'Coconut' }, - { id: 'cranberry', value: 'Cranberry' }, - { id: 'dragonfruit', value: 'Dragonfruit' }, - { id: 'durian', value: 'Durian' }, - { id: 'elderberry', value: 'Elderberry' }, - { id: 'fig', value: 'Fig' }, - { id: 'gooseberry', value: 'Gooseberry' }, - { id: 'grape', value: 'Grape' }, - { id: 'grapefruit', value: 'Grapefruit' }, - { id: 'guava', value: 'Guava' }, - { id: 'honeydew', value: 'Honeydew' }, - { id: 'jackfruit', value: 'Jackfruit' }, - { id: 'kiwi', value: 'Kiwi' }, - { id: 'kumquat', value: 'Kumquat' }, - { id: 'lemon', value: 'Lemon' }, - { id: 'lime', value: 'Lime' }, - { id: 'longan', value: 'Longan' }, - { id: 'lychee', value: 'Lychee' }, - { id: 'mandarin', value: 'Mandarin' }, - { id: 'mango', value: 'Mango' }, - { id: 'mangosteen', value: 'Mangosteen' }, - { id: 'mulberry', value: 'Mulberry' }, - { id: 'nectarine', value: 'Nectarine' }, - { id: 'orange', value: 'Orange' }, - { id: 'papaya', value: 'Papaya' }, - { id: 'passionfruit', value: 'Passionfruit' }, - { id: 'peach', value: 'Peach' }, - { id: 'pear', value: 'Pear' }, - { id: 'persimmon', value: 'Persimmon' }, - { id: 'pineapple', value: 'Pineapple' }, - { id: 'plum', value: 'Plum' }, - { id: 'pomegranate', value: 'Pomegranate' }, - { id: 'quince', value: 'Quince' }, - { id: 'rambutan', value: 'Rambutan' }, - { id: 'raspberry', value: 'Raspberry' }, - { id: 'soursop', value: 'Soursop' }, - { id: 'starfruit', value: 'Starfruit' }, - { id: 'strawberry', value: 'Strawberry' }, - { id: 'tangerine', value: 'Tangerine' }, - { id: 'watermelon', value: 'Watermelon' }, + { value: 'apple', label: 'Apple' }, + { value: 'apricot', label: 'Apricot' }, + { value: 'banana', label: 'Banana' }, + { value: 'blackberry', label: 'Blackberry' }, + { value: 'blueberry', label: 'Blueberry' }, + { value: 'boysenberry', label: 'Boysenberry' }, + { value: 'breadfruit', label: 'Breadfruit' }, + { value: 'cantaloupe', label: 'Cantaloupe' }, + { value: 'cherry', label: 'Cherry' }, + { value: 'clementine', label: 'Clementine' }, + { value: 'coconut', label: 'Coconut' }, + { value: 'cranberry', label: 'Cranberry' }, + { value: 'dragonfruit', label: 'Dragonfruit' }, + { value: 'durian', label: 'Durian' }, + { value: 'elderberry', label: 'Elderberry' }, + { value: 'fig', label: 'Fig' }, + { value: 'gooseberry', label: 'Gooseberry' }, + { value: 'grape', label: 'Grape' }, + { value: 'grapefruit', label: 'Grapefruit' }, + { value: 'guava', label: 'Guava' }, + { value: 'honeydew', label: 'Honeydew' }, + { value: 'jackfruit', label: 'Jackfruit' }, + { value: 'kiwi', label: 'Kiwi' }, + { value: 'kumquat', label: 'Kumquat' }, + { value: 'lemon', label: 'Lemon' }, + { value: 'lime', label: 'Lime' }, + { value: 'longan', label: 'Longan' }, + { value: 'lychee', label: 'Lychee' }, + { value: 'mandarin', label: 'Mandarin' }, + { value: 'mango', label: 'Mango' }, + { value: 'mangosteen', label: 'Mangosteen' }, + { value: 'mulberry', label: 'Mulberry' }, + { value: 'nectarine', label: 'Nectarine' }, + { value: 'orange', label: 'Orange' }, + { value: 'papaya', label: 'Papaya' }, + { value: 'passionfruit', label: 'Passionfruit' }, + { value: 'peach', label: 'Peach' }, + { value: 'pear', label: 'Pear' }, + { value: 'persimmon', label: 'Persimmon' }, + { value: 'pineapple', label: 'Pineapple' }, + { value: 'plum', label: 'Plum' }, + { value: 'pomegranate', label: 'Pomegranate' }, + { value: 'quince', label: 'Quince' }, + { value: 'rambutan', label: 'Rambutan' }, + { value: 'raspberry', label: 'Raspberry' }, + { value: 'soursop', label: 'Soursop' }, + { value: 'starfruit', label: 'Starfruit' }, + { value: 'strawberry', label: 'Strawberry' }, + { value: 'tangerine', label: 'Tangerine' }, + { value: 'watermelon', label: 'Watermelon' }, ]; diff --git a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx index 349624ba864bdf..2d62ad9e344f9c 100644 --- a/packages/ui/src/form/primitives/combobox/stories/index.story.tsx +++ b/packages/ui/src/form/primitives/combobox/stories/index.story.tsx @@ -56,10 +56,10 @@ export const Default: Story = { { ( item: FixtureItem ) => ( - { item.value } + { item.label } ) } @@ -88,11 +88,11 @@ export const Compact: Story = { { ( item: FixtureItem ) => ( - { item.value } + { item.label } ) } @@ -131,8 +131,11 @@ export const DetachedInline: Story = { { ( item: FixtureItem ) => ( - - { item.value } + + { item.label } ) } @@ -149,10 +152,10 @@ export const Creatable: Story = { const [ value, setValue ] = useState( ITEMS[ 0 ] ); const hasNoExactMatch = inputValue.length > 0 && - ! ITEMS.some( ( item ) => item.value === inputValue.trim() ); + ! ITEMS.some( ( item ) => item.label === inputValue.trim() ); const creatableItem = { - id: 'create', - value: + value: 'create', + label: 'Create new item' + ( inputValue ? `: ${ inputValue }` : '' ), }; @@ -164,7 +167,7 @@ export const Creatable: Story = { value={ value } onValueChange={ ( newValue, event ) => { const typedValue = newValue as FixtureItem; - if ( typedValue.id === 'create' ) { + if ( typedValue.value === 'create' ) { // eslint-disable-next-line no-alert alert( 'Show dialog to create new item!' ); } else { @@ -188,12 +191,12 @@ export const Creatable: Story = { { ( item: FixtureItem ) => - item.id !== creatableItem.id && ( + item.value !== creatableItem.value && ( - { item.value } + { item.label } ) } @@ -203,9 +206,9 @@ export const Creatable: Story = { - { creatableItem.value } + { creatableItem.label } @@ -218,8 +221,8 @@ export const Creatable: Story = { export const AsyncItems: Story = { render: function Template( args ) { const LOADING_ITEM = { - id: 'loading', - value: 'Loading...', + value: 'loading', + label: 'Loading...', }; const [ items, setItems ] = useState( [ LOADING_ITEM ] ); const [ value, setValue ] = useState< unknown >( LOADING_ITEM ); @@ -251,11 +254,11 @@ export const AsyncItems: Story = { { ( item: FixtureItem ) => ( - { item.value } + { item.label } ) } @@ -289,14 +292,14 @@ export const WithCustomTriggerAndItem: Story = { } } > - { item.value } + { item.label } ) }
@@ -309,9 +312,9 @@ export const WithCustomTriggerAndItem: Story = { { ( item: FixtureItem ) => (
- { item.value } + { item.label }