From 3513478fb6949f49580ee8b8c2497a806a65fba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 16 Apr 2020 22:04:53 +0200 Subject: [PATCH] fix(docsearch): update search suggestions when new lvl0s are encountered --- src/DocSearch.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DocSearch.tsx b/src/DocSearch.tsx index 54d6579f..9776fcd6 100644 --- a/src/DocSearch.tsx +++ b/src/DocSearch.tsx @@ -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), });