Skip to content

Commit

Permalink
fix(js): display empty template only with a query
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Feb 11, 2021
1 parent 5accc82 commit 7c2f9a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions packages/autocomplete-js/src/autocomplete.ts
Expand Up @@ -39,21 +39,6 @@ export function autocomplete<TItem extends BaseItem>(
const isDetached = reactive(
() => window.matchMedia(props.value.renderer.detachedMediaQuery).matches
);
const shouldPanelOpen =
optionsRef.current.shouldPanelOpen ||
(({ state }) => {
const hasItems = getItemsCount(state) > 0;

if (!props.value.core.openOnFocus && !state.query) {
return hasItems;
}

const hasEmptyTemplate = Boolean(
hasEmptySourceTemplateRef.current || props.value.renderer.renderEmpty
);

return (!hasItems && hasEmptyTemplate) || hasItems;
});
const autocomplete = reactive(() =>
createAutocomplete<TItem>({
...props.value.core,
Expand All @@ -65,7 +50,22 @@ export function autocomplete<TItem extends BaseItem>(
onStateChangeRef.current?.(options as any);
props.value.core.onStateChange?.(options as any);
},
shouldPanelOpen: isDetached ? () => true : shouldPanelOpen,
shouldPanelOpen:
optionsRef.current.shouldPanelOpen ||
(({ state }) => {
const hasItems = getItemsCount(state) > 0;

if (!props.value.core.openOnFocus && !state.query) {
return hasItems;
}

const hasEmptyTemplate = Boolean(
hasEmptySourceTemplateRef.current ||
props.value.renderer.renderEmpty
);

return (!hasItems && hasEmptyTemplate) || hasItems;
}),
})
);
const lastStateRef = createRef<AutocompleteState<TItem>>({
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-js/src/render.tsx
Expand Up @@ -105,7 +105,7 @@ export function renderPanel<TItem extends BaseItem>(
</div>
)}

{items.length === 0 && source.templates.empty ? (
{items.length === 0 && source.templates.empty && state.query ? (
<div className={classNames.sourceEmpty}>
{source.templates.empty({
createElement,
Expand Down

0 comments on commit 7c2f9a3

Please sign in to comment.