From f2c3eb2d5ec6e5338df5b685af8edfb6cc477659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Wed, 12 Feb 2020 15:35:58 +0100 Subject: [PATCH] feat(core): rename `shouldDropdownOpen` to `shouldDropdownShow` See https://github.com/francoischalifour/autocomplete.js/pull/16#pullrequestreview-355978230 --- README.md | 4 ++-- packages/autocomplete-core/defaultProps.ts | 2 +- packages/autocomplete-core/onInput.ts | 4 ++-- packages/autocomplete-core/types/api.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) 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; }