Skip to content

Commit

Permalink
fix(docsearch): update search suggestions when new lvl0s are encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 16, 2020
1 parent 4f96cdb commit 3513478
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/DocSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export function DocSearch({
openOnFocus: true,
initialState: {
query: initialQuery,
context: {
searchSuggestions: [],
},
},
navigator,
onStateChange({ state }) {
Expand Down Expand Up @@ -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),
});
Expand Down

0 comments on commit 3513478

Please sign in to comment.