Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,54 @@ describe( 'Autocomplete', () => {
} );
} );

it( 'places inline list parts in the grid of the consumer', async () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is worth testing because it has the potential to regress in future iterations, and partial regressions (like with Empty) may not be immediately obvious in Storybook.

await render(
<Autocomplete.Root items={ ITEMS } inline open>
<Autocomplete.Input placeholder="Search" />
<div
data-testid="wrapper"
style={ {
display: 'grid',
gridTemplateRows: 'auto minmax(0, 1fr)',
height: 200,
} }
>
<Autocomplete.Empty>No results.</Autocomplete.Empty>
<Autocomplete.List>
<Autocomplete.Collection>
{ ( item: ( typeof ITEMS )[ number ] ) => (
<Autocomplete.Item
key={ item.id }
value={ item }
>
<Autocomplete.ItemLabel>
{ item.value }
</Autocomplete.ItemLabel>
</Autocomplete.Item>
) }
</Autocomplete.Collection>
</Autocomplete.List>
</div>
</Autocomplete.Root>
);

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 = [
{
Expand Down
30 changes: 17 additions & 13 deletions packages/ui/src/utils/css/item-popup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading