Skip to content

Commit

Permalink
search: fix results not disappearing
Browse files Browse the repository at this point in the history
Fixes #158.

Also fixes a react error about missing unique keys on the highlighted texts.
  • Loading branch information
zsol committed May 26, 2024
1 parent b2b63ea commit 141caae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions www/components/core/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ interface MatchProps {
result: Result;
}

function highlightCallback(highlighted: string, _ind: number): ReactElement {
return <b>{highlighted}</b>;
function highlightCallback(highlighted: string, ind: number): ReactElement {
return <b key={ind}>{highlighted}</b>;
}

function Match({ result }: MatchProps): ReactElement {
Expand Down Expand Up @@ -99,14 +99,15 @@ export const Search = ({ descriptors }: SearchParams) => {
onChange={(event) => {
setSearchTerm(event.target.value);
}}
value={searchTerm}
/>
{searchTerm && results && (
<SearchResultContainer>
{results.total === 0 && "No results found"}
{results.total > 0 &&
results.map((result: Result, ind: number) => (
<SearchResultItem key={`${result.obj.name}_${ind}`}>
<ItemLink to={`${result.obj.url}`}>
<ItemLink to={`${result.obj.url}`} onClick={(event) => setSearchTerm("")}>
<Match result={result} />
</ItemLink>
</SearchResultItem>
Expand Down

0 comments on commit 141caae

Please sign in to comment.