From d7d698476246d76f1038415c960877774314eb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Sat, 4 Apr 2020 12:40:40 +0200 Subject: [PATCH] fix(docsearch): hide search suggestions if none --- src/NoResultsScreen.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/NoResultsScreen.tsx b/src/NoResultsScreen.tsx index 01f73cb78..1fa839b6e 100644 --- a/src/NoResultsScreen.tsx +++ b/src/NoResultsScreen.tsx @@ -18,17 +18,18 @@ interface NoResultsScreenProps } export function NoResultsScreen(props: NoResultsScreenProps) { + const searchSuggestions: string[] = props.state.context.searchSuggestions; + return (

No results for "{props.state.query}".

-

- Try searching for{' '} - {(props.state.context.searchSuggestions as string[]) - .slice(0, 3) - .reduce( + {searchSuggestions.length > 0 && ( +

+ Try searching for{' '} + {searchSuggestions.slice(0, 3).reduce( (acc, search) => [ ...acc, acc.length > 0 ? ', ' : '', @@ -46,8 +47,9 @@ export function NoResultsScreen(props: NoResultsScreenProps) { ], [] )} -  ... -

+  ... +

+ )}

If you believe this query should return results,