diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md index c6d8dd4132b9e9..c2be79230ac46f 100644 --- a/packages/ui/CHANGELOG.md +++ b/packages/ui/CHANGELOG.md @@ -21,6 +21,7 @@ ### Bug Fixes +- `Autocomplete` and `Combobox`: Place an inline `List`, `Empty`, or `Status` in a surrounding CSS grid like any other child, instead of in an extra implicit row and column ([#86652](https://github.com/WordPress/gutenberg/pull/86652)). - `Combobox` and `Autocomplete`: Keep `ListBody` out of the Tab order, so a scrolling inline list is no longer an extra Tab stop after the input ([#86535](https://github.com/WordPress/gutenberg/pull/86535)). - `AlertDialog`: Honor canceled open state changes and restore usable controls when closing after confirmation is canceled ([#86544](https://github.com/WordPress/gutenberg/pull/86544)). - `Textarea`: Fix ref and render prop composition, restoring Field filled state, required validation, and returning to pristine when the default value is restored ([#86546](https://github.com/WordPress/gutenberg/pull/86546)). diff --git a/packages/ui/src/form/primitives/autocomplete/test/index.browser.test.tsx b/packages/ui/src/form/primitives/autocomplete/test/index.browser.test.tsx index 7519fc5459fb28..444eb37fdaf3d8 100644 --- a/packages/ui/src/form/primitives/autocomplete/test/index.browser.test.tsx +++ b/packages/ui/src/form/primitives/autocomplete/test/index.browser.test.tsx @@ -436,6 +436,54 @@ describe( 'Autocomplete', () => { } ); } ); + it( 'places inline list parts in the grid of the consumer', async () => { + await render( + + +
+ No results. + + + { ( item: ( typeof ITEMS )[ number ] ) => ( + + + { item.value } + + + ) } + + +
+
+ ); + + const wrapperRect = screen + .getByTestId( 'wrapper' ) + .getBoundingClientRect(); + const listRect = screen.getByRole( 'listbox' ).getBoundingClientRect(); + + // The empty state is collapsed, so the list fills the second row. + expect( listRect.top ).toBeCloseTo( wrapperRect.top ); + expect( listRect.bottom ).toBeCloseTo( wrapperRect.bottom ); + + await userEvent.type( screen.getByRole( 'combobox' ), 'zzz' ); + const emptyRect = ( + await screen.findByText( 'No results.' ) + ).getBoundingClientRect(); + + expect( emptyRect.top ).toBeCloseTo( wrapperRect.top ); + } ); + describe( 'grouped items', () => { const GROUPED_ITEMS = [ { diff --git a/packages/ui/src/utils/css/item-popup.module.css b/packages/ui/src/utils/css/item-popup.module.css index 0009ade816d16a..f2b902794e7dc8 100644 --- a/packages/ui/src/utils/css/item-popup.module.css +++ b/packages/ui/src/utils/css/item-popup.module.css @@ -69,14 +69,12 @@ } /* - * Slot and typography styles for a list in `.popup`'s `main` grid area. - * Combobox and Autocomplete get this via `.list`. Select applies - * it directly so Select.List can own overflow. + * Typography styles for an item list. Combobox and Autocomplete get this + * via `.list`. Select applies it directly so Select.List can own overflow. */ .list-chrome { --_wp-ui-popup-selection-offset: 0px; - grid-area: main; font-family: var(--wpds-typography-font-family-body); font-size: var(--wpds-typography-font-size-md); line-height: var(--wpds-typography-line-height-sm); @@ -296,20 +294,26 @@ color: var(--wpds-color-foreground-content-neutral-weak); } - .status { - grid-area: status; - - &:has(.loading-indicator) { - padding-block: var(--wp-ui-popup-padding); - } + .status:has(.loading-indicator) { + padding-block: var(--wp-ui-popup-padding); } - /* Empty shares main with the list. A VisuallyHidden child still makes - Status :not(:empty). Chrome only when it would not cover the list. */ - .empty:not(:empty) { + /* + * The named grid areas exist only in `.popup`, so inline parts follow + * the layout they are placed in. `:where()` keeps the specificity. + * Empty shares main with the list. + */ + :where(.popup) .list-chrome, + :where(.popup) .empty:not(:empty) { grid-area: main; } + :where(.popup) .status { + grid-area: status; + } + + /* A VisuallyHidden child still makes Status :not(:empty). Chrome only + when it would not cover the list. */ .empty:not(:empty), .status:not(:empty):not(:has([data-visually-hidden], .loading-indicator)) { --wp-ui-popup-empty-min-height: var(--wpds-dimension-size-md);