Skip to content

Commit

Permalink
fix(core): rename shouldPanelShow to shouldPanelOpen
Browse files Browse the repository at this point in the history
This new name is more aligned with the `isOpen` state getter.
  • Loading branch information
francoischalifour committed Feb 9, 2021
1 parent 3827605 commit c442884
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/getDefaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getDefaultProps<TItem extends BaseItem>(
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.
Expand Down
10 changes: 5 additions & 5 deletions packages/autocomplete-core/src/onInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function onInput<TItem extends BaseItem>({
}))
);
setIsOpen(
nextState.isOpen ?? props.shouldPanelShow({ state: store.getState() })
nextState.isOpen ?? props.shouldPanelOpen({ state: store.getState() })
);

return Promise.resolve();
Expand Down Expand Up @@ -107,12 +107,12 @@ export function onInput<TItem extends BaseItem>({
.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());
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-core/src/types/AutocompleteOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export interface AutocompleteOptions<TItem extends BaseItem> {
/**
* The function called to determine whether the panel should open.
*/
shouldPanelShow?(params: { state: AutocompleteState<TItem> }): boolean;
shouldPanelOpen?(params: { state: AutocompleteState<TItem> }): boolean;
/**
* The function called when the Autocomplete form is submitted.
*/
Expand Down Expand Up @@ -144,7 +144,7 @@ export interface InternalAutocompleteOptions<TItem extends BaseItem>
environment: AutocompleteEnvironment;
navigator: AutocompleteNavigator<TItem>;
plugins: Array<AutocompletePlugin<TItem, unknown>>;
shouldPanelShow(params: { state: AutocompleteState<TItem> }): boolean;
shouldPanelOpen(params: { state: AutocompleteState<TItem> }): boolean;
onSubmit(params: OnSubmitParams<TItem>): void;
onReset(params: OnResetParams<TItem>): void;
onInput?(params: OnInputParams<TItem>): void | Promise<any>;
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-js/src/__tests__/autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,15 @@ describe('autocomplete-js', () => {
});
});

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

document.body.appendChild(panelContainer);
autocomplete<{ label: string }>({
container,
panelContainer,
shouldPanelShow: () => false,
shouldPanelOpen: () => false,
getSources() {
return [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-js/src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function autocomplete<TItem extends BaseItem>(
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;

Expand Down
2 changes: 1 addition & 1 deletion packages/website/docs/partials/createAutocomplete-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit c442884

Please sign in to comment.