Skip to content

Commit

Permalink
ComboboxControl: Add an isLoading prop to show a loading spinner (W…
Browse files Browse the repository at this point in the history
…ordPress#68990)


Co-authored-by: adamsilverstein <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ciampo <[email protected]>
  • Loading branch information
4 people authored Feb 5, 2025
1 parent b0e328f commit 589e763
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- `ComboboxControl`: Add an `isLoading` prop to show a loading spinner ([#68990](https://github.com/WordPress/gutenberg/pull/68990))

## 29.3.0 (2025-01-29)

### Enhancements
Expand Down
10 changes: 9 additions & 1 deletion packages/components/src/combobox-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function MyComboboxControl() {
label="Font Size"
value={ fontSize }
onChange={ setFontSize }
isLoading={ isLoading }
options={ filteredOptions }
onFilterValueChange={ ( inputValue ) =>
setFilteredOptions(
Expand Down Expand Up @@ -112,13 +113,20 @@ If the control is clicked, the dropdown will expand regardless of this prop.
- Required: No
- Default: `true`

### placeholder
#### placeholder

If passed, the combobox input will show a placeholder string if no values are present.

- Type: `string`
- Required: No

#### isLoading

Show a spinner (and hide the suggestions dropdown) while data about the matching suggestions (ie the `options` prop) is loading

- Type: `Boolean`
- Required: No

#### __experimentalRenderItem

Custom renderer invoked for each option in the suggestion list. The render prop receives as its argument an object containing, under the `item` key, the single option's data (directly from the array of data passed to the `options` prop).
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/combobox-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { TokenInputProps } from '../form-token-field/types';
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';
import Spinner from '../spinner';

const noop = () => {};

Expand Down Expand Up @@ -126,6 +127,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
help,
allowReset = true,
className,
isLoading = false,
messages = {
selected: __( 'Item selected.' ),
},
Expand Down Expand Up @@ -362,6 +364,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
onChange={ onInputChange }
/>
</FlexBlock>
{ isLoading && <Spinner /> }
{ allowReset && (
<Button
size="small"
Expand All @@ -375,7 +378,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
/>
) }
</InputWrapperFlex>
{ isExpanded && (
{ isExpanded && ! isLoading && (
<SuggestionsList
instanceId={ instanceId }
// The empty string for `value` here is not actually used, but is
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/combobox-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ input.components-combobox-control__input[type="text"] {
&:focus-within {
@include input-style__focus();
}
}

.components-spinner {
margin: 0;
}
}
7 changes: 7 additions & 0 deletions packages/components/src/combobox-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ export type ComboboxControlProps = Pick<
* If passed, the combobox input will show a placeholder string if no values are present.
*/
placeholder?: string;
/**
* Show a spinner (and hide the suggestions dropdown) while data
* about the matching suggestions (ie the `options` prop) is loading
*
* @default false
*/
isLoading?: boolean;
};

0 comments on commit 589e763

Please sign in to comment.