Skip to content

Commit

Permalink
fix: able to render html as a link within the search bar
Browse files Browse the repository at this point in the history
description:
When a user inputs text into the search bar field, a request is sent to 'Pandosearch'.
The response received includes both HTML and text content. For instance,
 if the user searches for "search", the resulting response might contain
 "<b>Search</b>" or "<mark>Search</mark>".
  • Loading branch information
AliKdhim87 committed Sep 1, 2023
1 parent 8d42f61 commit 1b17160
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions apps/pdc-frontend/src/components/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface SearchBarProps {
}

const itemToString = (item: any) => {
return item ? item.text || item.title : '';
return item ? item.text || item.titleRaw : '';
};

export const SearchBar: React.FC<SearchBarProps> = ({
Expand Down Expand Up @@ -95,18 +95,15 @@ export const SearchBar: React.FC<SearchBarProps> = ({
itemToString={itemToString}
renderOptions={(option) => {
if (option.type === 'page') {
return (
<UtrechtLink external href={option.url}>
{option.title}
</UtrechtLink>
);
return <UtrechtLink external href={option.url} dangerouslySetInnerHTML={{ __html: option.title }} />;
}

return (
option?.text && (
<Link className={classNames('utrecht-link', 'utrecht-link--external')} href={`/search/${option?.text}`}>
{option?.text}
</Link>
<Link
className={classNames('utrecht-link', 'utrecht-link--external')}
href={`/search/${option?.text}`}
dangerouslySetInnerHTML={{ __html: option?.text }}
/>
)
);
}}
Expand Down

0 comments on commit 1b17160

Please sign in to comment.