createAutocomplete closes panel if there are no results #1020
Replies: 4 comments
-
Hi @JoeVanGundy, This is the expected behavior. You don't have to implement this option to re-create the Slack experience though—instead, check the length of your As a sidenote, implementing this behavior would be a lot easier using |
Beta Was this translation helpful? Give feedback.
-
Hey @sarahdayan , thanks for the response! I have the panel itself behind a check like this:
Wouldn't the check for The main factors that led to using
Also it would be huge if it's possible to share the code for the Algolia Documentation Command Palette. Let me know if there's any other insight that could help! (We're loving Autocomplete, so these aren't complaints, but just hopefully an insight into our decision) |
Beta Was this translation helpful? Give feedback.
-
Hi @JoeVanGundy and sorry for the late answer. The check on item's length that I was suggesting wasn't to decide whether to display the panel, but to return alternative sources when the main one doesn't return results. Here's what' it could look like with autocomplete({
// …
getSources({ query }) {
return [
{
sourceId: 'products',
getItems({ query }) {
return getAlgoliaResults({
// …
transformResponse({ hits }) {
if (hits.length === 0) {
return [
{
title: 'Some alternative search result',
},
];
}
return hits;
},
});
},
// …
},
];
},
}); When there are no Regarding your usage of
I'm going to close this since this isn't an issue and convert it to a discussion, feel free to keep it going! |
Beta Was this translation helpful? Give feedback.
-
Description
If there are no results for a search, the panel is closed.
Not sure if there is a way to avoid this, but I can't find any way to override this.
Reproduction
https://codesandbox.io/s/github/algolia/autocomplete/tree/next/examples/react-renderer?file=/src/Autocomplete.tsx
Steps
Expected behavior
My expectation is that I'd be able to show a
No results
kind of message.Environment
Beta Was this translation helpful? Give feedback.
All reactions