1
0
Fork 0

fix(docsearch): update search suggestions when new lvl0s are encountered

This commit is contained in:
François Chalifour 2020-04-16 22:04:53 +02:00
parent 4f96cdb622
commit 3513478fb6

View file

@ -118,6 +118,9 @@ export function DocSearch({
openOnFocus: true,
initialState: {
query: initialQuery,
context: {
searchSuggestions: [],
},
},
navigator,
onStateChange({ state }) {
@ -207,7 +210,10 @@ export function DocSearch({
// We store the `lvl0`s to display them as search suggestions
// in the “no results“ screen.
if (state.context.searchSuggestions === undefined) {
if (
(state.context.searchSuggestions as any[]).length <
Object.keys(sources).length
) {
setContext({
searchSuggestions: Object.keys(sources),
});