Skip to content

Commit c442884

Browse files
fix(core): rename shouldPanelShow to shouldPanelOpen
This new name is more aligned with the `isOpen` state getter.
1 parent 3827605 commit c442884

6 files changed

Lines changed: 13 additions & 13 deletions

File tree

packages/autocomplete-core/src/getDefaultProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function getDefaultProps<TItem extends BaseItem>(
2626
defaultActiveItemId: null,
2727
stallThreshold: 300,
2828
environment,
29-
shouldPanelShow: ({ state }) => getItemsCount(state) > 0,
29+
shouldPanelOpen: ({ state }) => getItemsCount(state) > 0,
3030
...props,
3131
// Since `generateAutocompleteId` triggers a side effect (it increments
3232
// and internal counter), we don't want to execute it if unnecessary.

packages/autocomplete-core/src/onInput.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function onInput<TItem extends BaseItem>({
6060
}))
6161
);
6262
setIsOpen(
63-
nextState.isOpen ?? props.shouldPanelShow({ state: store.getState() })
63+
nextState.isOpen ?? props.shouldPanelOpen({ state: store.getState() })
6464
);
6565

6666
return Promise.resolve();
@@ -107,12 +107,12 @@ export function onInput<TItem extends BaseItem>({
107107
.then((collections) => {
108108
setStatus('idle');
109109
setCollections(collections as any);
110+
const isPanelOpen = props.shouldPanelOpen({
111+
state: store.getState(),
112+
});
110113
setIsOpen(
111114
nextState.isOpen ??
112-
((props.openOnFocus &&
113-
!query &&
114-
props.shouldPanelShow({ state: store.getState() })) ||
115-
props.shouldPanelShow({ state: store.getState() }))
115+
((props.openOnFocus && !query && isPanelOpen) || isPanelOpen)
116116
);
117117

118118
const highlightedItem = getActiveItem(store.getState());

packages/autocomplete-core/src/types/AutocompleteOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export interface AutocompleteOptions<TItem extends BaseItem> {
113113
/**
114114
* The function called to determine whether the panel should open.
115115
*/
116-
shouldPanelShow?(params: { state: AutocompleteState<TItem> }): boolean;
116+
shouldPanelOpen?(params: { state: AutocompleteState<TItem> }): boolean;
117117
/**
118118
* The function called when the Autocomplete form is submitted.
119119
*/
@@ -144,7 +144,7 @@ export interface InternalAutocompleteOptions<TItem extends BaseItem>
144144
environment: AutocompleteEnvironment;
145145
navigator: AutocompleteNavigator<TItem>;
146146
plugins: Array<AutocompletePlugin<TItem, unknown>>;
147-
shouldPanelShow(params: { state: AutocompleteState<TItem> }): boolean;
147+
shouldPanelOpen(params: { state: AutocompleteState<TItem> }): boolean;
148148
onSubmit(params: OnSubmitParams<TItem>): void;
149149
onReset(params: OnResetParams<TItem>): void;
150150
onInput?(params: OnInputParams<TItem>): void | Promise<any>;

packages/autocomplete-js/src/__tests__/autocomplete.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ describe('autocomplete-js', () => {
377377
});
378378
});
379379

380-
test('allows user-provided shouldPanelShow', () => {
380+
test('allows user-provided shouldPanelOpen', () => {
381381
const container = document.createElement('div');
382382
const panelContainer = document.createElement('div');
383383

384384
document.body.appendChild(panelContainer);
385385
autocomplete<{ label: string }>({
386386
container,
387387
panelContainer,
388-
shouldPanelShow: () => false,
388+
shouldPanelOpen: () => false,
389389
getSources() {
390390
return [
391391
{

packages/autocomplete-js/src/autocomplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export function autocomplete<TItem extends BaseItem>(
4747
onStateChangeRef.current?.(options as any);
4848
props.value.core.onStateChange?.(options as any);
4949
},
50-
shouldPanelShow:
51-
optionsRef.current.shouldPanelShow ||
50+
shouldPanelOpen:
51+
optionsRef.current.shouldPanelOpen ||
5252
(({ state }) => {
5353
const hasItems = getItemsCount(state) > 0;
5454

packages/website/docs/partials/createAutocomplete-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Navigator API to redirect the user when a link should be opened.
7070

7171
Learn more on the [Navigator API](/docs/keyboard-navigation) documentation.
7272

73-
### `shouldPanelShow`
73+
### `shouldPanelOpen`
7474

7575
> `(params: { state: AutocompleteState }) => boolean`
7676

0 commit comments

Comments
 (0)