Skip to content

Commit 141caae

Browse files
committed
search: fix results not disappearing
Fixes #158. Also fixes a react error about missing unique keys on the highlighted texts.
1 parent b2b63ea commit 141caae

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

www/components/core/Search.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ interface MatchProps {
4949
result: Result;
5050
}
5151

52-
function highlightCallback(highlighted: string, _ind: number): ReactElement {
53-
return <b>{highlighted}</b>;
52+
function highlightCallback(highlighted: string, ind: number): ReactElement {
53+
return <b key={ind}>{highlighted}</b>;
5454
}
5555

5656
function Match({ result }: MatchProps): ReactElement {
@@ -99,14 +99,15 @@ export const Search = ({ descriptors }: SearchParams) => {
9999
onChange={(event) => {
100100
setSearchTerm(event.target.value);
101101
}}
102+
value={searchTerm}
102103
/>
103104
{searchTerm && results && (
104105
<SearchResultContainer>
105106
{results.total === 0 && "No results found"}
106107
{results.total > 0 &&
107108
results.map((result: Result, ind: number) => (
108109
<SearchResultItem key={`${result.obj.name}_${ind}`}>
109-
<ItemLink to={`${result.obj.url}`}>
110+
<ItemLink to={`${result.obj.url}`} onClick={(event) => setSearchTerm("")}>
110111
<Match result={result} />
111112
</ItemLink>
112113
</SearchResultItem>

0 commit comments

Comments
 (0)