Skip to content

Commit

Permalink
search: fix results not disappearing (#166)
Browse files Browse the repository at this point in the history
* search: fix results not disappearing


Fixes #158.

Also fixes a react error about missing unique keys on the highlighted texts.

* Commit from GitHub Actions (Applying autofixes)

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
zsol and github-actions[bot] committed May 27, 2024
1 parent b2b63ea commit 99fa363
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 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,18 @@ 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 99fa363

Please sign in to comment.