diff --git a/README.md b/README.md index 383eec140..5fc1dc0bf 100644 --- a/README.md +++ b/README.md @@ -407,9 +407,9 @@ Called when the input changes. This turns experience is "controlled" mode. You'll be in charge of updating the state with the [top-level API](#autocomplete). -#### `shouldDropdownOpen` +#### `shouldDropdownShow` -> `(options: { state: AutocompleteState }) => boolean` | defaults to `({ state }) => state.results.some(result => result.suggestions.length > 0)` +> `(options: { state: AutocompleteState }) => boolean` | defaults to `({ state }) => state.suggestions.some(suggestion => suggestion.items.length > 0)` Called to check whether the dropdown should open based on the Autocomplete state. diff --git a/packages/autocomplete-core/defaultProps.ts b/packages/autocomplete-core/defaultProps.ts index 687d88da4..df700b061 100644 --- a/packages/autocomplete-core/defaultProps.ts +++ b/packages/autocomplete-core/defaultProps.ts @@ -22,7 +22,7 @@ export function getDefaultProps( showCompletion: false, stallThreshold: 300, environment, - shouldDropdownOpen: ({ state }) => getItemsCount(state) > 0, + shouldDropdownShow: ({ state }) => getItemsCount(state) > 0, onStateChange: noop, onSubmit: noop, ...props, diff --git a/packages/autocomplete-core/onInput.ts b/packages/autocomplete-core/onInput.ts index c944d0666..c0ec3dcbd 100644 --- a/packages/autocomplete-core/onInput.ts +++ b/packages/autocomplete-core/onInput.ts @@ -49,7 +49,7 @@ export function onInput({ })) ); setIsOpen( - nextState.isOpen ?? props.shouldDropdownOpen({ state: store.getState() }) + nextState.isOpen ?? props.shouldDropdownShow({ state: store.getState() }) ); return; @@ -103,7 +103,7 @@ export function onInput({ setIsOpen( nextState.isOpen ?? (query.length >= props.minLength && - props.shouldDropdownOpen({ state: store.getState() })) + props.shouldDropdownShow({ state: store.getState() })) ); }) .catch(error => { diff --git a/packages/autocomplete-core/types/api.ts b/packages/autocomplete-core/types/api.ts index e2b8e2274..5ba1f8892 100644 --- a/packages/autocomplete-core/types/api.ts +++ b/packages/autocomplete-core/types/api.ts @@ -181,7 +181,7 @@ export interface PublicAutocompleteOptions { /** * The function called to determine whether the dropdown should open. */ - shouldDropdownOpen?(options: { state: AutocompleteState }): boolean; + shouldDropdownShow?(options: { state: AutocompleteState }): boolean; /** * The function called when the autocomplete form is submitted. */ @@ -202,6 +202,6 @@ export interface AutocompleteOptions { getSources: GetSources; environment: Environment; navigator: Navigator; - shouldDropdownOpen(options: { state: AutocompleteState }): boolean; + shouldDropdownShow(options: { state: AutocompleteState }): boolean; onSubmit(params: EventHandlerParams): void; }