diff --git a/packages/autocomplete-core/src/getDefaultProps.ts b/packages/autocomplete-core/src/getDefaultProps.ts index 69eb4657a..d09d48979 100644 --- a/packages/autocomplete-core/src/getDefaultProps.ts +++ b/packages/autocomplete-core/src/getDefaultProps.ts @@ -26,7 +26,7 @@ export function getDefaultProps( defaultActiveItemId: null, stallThreshold: 300, environment, - shouldPanelShow: ({ state }) => getItemsCount(state) > 0, + shouldPanelOpen: ({ state }) => getItemsCount(state) > 0, ...props, // Since `generateAutocompleteId` triggers a side effect (it increments // and internal counter), we don't want to execute it if unnecessary. diff --git a/packages/autocomplete-core/src/onInput.ts b/packages/autocomplete-core/src/onInput.ts index 3564a2127..575f356d9 100644 --- a/packages/autocomplete-core/src/onInput.ts +++ b/packages/autocomplete-core/src/onInput.ts @@ -60,7 +60,7 @@ export function onInput({ })) ); setIsOpen( - nextState.isOpen ?? props.shouldPanelShow({ state: store.getState() }) + nextState.isOpen ?? props.shouldPanelOpen({ state: store.getState() }) ); return Promise.resolve(); @@ -107,12 +107,12 @@ export function onInput({ .then((collections) => { setStatus('idle'); setCollections(collections as any); + const isPanelOpen = props.shouldPanelOpen({ + state: store.getState(), + }); setIsOpen( nextState.isOpen ?? - ((props.openOnFocus && - !query && - props.shouldPanelShow({ state: store.getState() })) || - props.shouldPanelShow({ state: store.getState() })) + ((props.openOnFocus && !query && isPanelOpen) || isPanelOpen) ); const highlightedItem = getActiveItem(store.getState()); diff --git a/packages/autocomplete-core/src/types/AutocompleteOptions.ts b/packages/autocomplete-core/src/types/AutocompleteOptions.ts index e195967d3..881412400 100644 --- a/packages/autocomplete-core/src/types/AutocompleteOptions.ts +++ b/packages/autocomplete-core/src/types/AutocompleteOptions.ts @@ -113,7 +113,7 @@ export interface AutocompleteOptions { /** * The function called to determine whether the panel should open. */ - shouldPanelShow?(params: { state: AutocompleteState }): boolean; + shouldPanelOpen?(params: { state: AutocompleteState }): boolean; /** * The function called when the Autocomplete form is submitted. */ @@ -144,7 +144,7 @@ export interface InternalAutocompleteOptions environment: AutocompleteEnvironment; navigator: AutocompleteNavigator; plugins: Array>; - shouldPanelShow(params: { state: AutocompleteState }): boolean; + shouldPanelOpen(params: { state: AutocompleteState }): boolean; onSubmit(params: OnSubmitParams): void; onReset(params: OnResetParams): void; onInput?(params: OnInputParams): void | Promise; diff --git a/packages/autocomplete-js/src/__tests__/autocomplete.test.ts b/packages/autocomplete-js/src/__tests__/autocomplete.test.ts index 5bd5c03ef..4dc2dd635 100644 --- a/packages/autocomplete-js/src/__tests__/autocomplete.test.ts +++ b/packages/autocomplete-js/src/__tests__/autocomplete.test.ts @@ -377,7 +377,7 @@ describe('autocomplete-js', () => { }); }); - test('allows user-provided shouldPanelShow', () => { + test('allows user-provided shouldPanelOpen', () => { const container = document.createElement('div'); const panelContainer = document.createElement('div'); @@ -385,7 +385,7 @@ describe('autocomplete-js', () => { autocomplete<{ label: string }>({ container, panelContainer, - shouldPanelShow: () => false, + shouldPanelOpen: () => false, getSources() { return [ { diff --git a/packages/autocomplete-js/src/autocomplete.ts b/packages/autocomplete-js/src/autocomplete.ts index 0701c0e4d..737a58c7b 100644 --- a/packages/autocomplete-js/src/autocomplete.ts +++ b/packages/autocomplete-js/src/autocomplete.ts @@ -47,8 +47,8 @@ export function autocomplete( onStateChangeRef.current?.(options as any); props.value.core.onStateChange?.(options as any); }, - shouldPanelShow: - optionsRef.current.shouldPanelShow || + shouldPanelOpen: + optionsRef.current.shouldPanelOpen || (({ state }) => { const hasItems = getItemsCount(state) > 0; diff --git a/packages/website/docs/partials/createAutocomplete-props.md b/packages/website/docs/partials/createAutocomplete-props.md index 92d22cf27..ac55279dc 100644 --- a/packages/website/docs/partials/createAutocomplete-props.md +++ b/packages/website/docs/partials/createAutocomplete-props.md @@ -70,7 +70,7 @@ Navigator API to redirect the user when a link should be opened. Learn more on the [Navigator API](/docs/keyboard-navigation) documentation. -### `shouldPanelShow` +### `shouldPanelOpen` > `(params: { state: AutocompleteState }) => boolean`