Skip to content

Commit 1b17160

Browse files
committed
fix: able to render html as a link within the search bar
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>".
1 parent 8d42f61 commit 1b17160

File tree

1 file changed

+7
-10
lines changed
  • apps/pdc-frontend/src/components/SearchBar

1 file changed

+7
-10
lines changed

apps/pdc-frontend/src/components/SearchBar/index.tsx

+7-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface SearchBarProps {
2424
}
2525

2626
const itemToString = (item: any) => {
27-
return item ? item.text || item.title : '';
27+
return item ? item.text || item.titleRaw : '';
2828
};
2929

3030
export const SearchBar: React.FC<SearchBarProps> = ({
@@ -95,18 +95,15 @@ export const SearchBar: React.FC<SearchBarProps> = ({
9595
itemToString={itemToString}
9696
renderOptions={(option) => {
9797
if (option.type === 'page') {
98-
return (
99-
<UtrechtLink external href={option.url}>
100-
{option.title}
101-
</UtrechtLink>
102-
);
98+
return <UtrechtLink external href={option.url} dangerouslySetInnerHTML={{ __html: option.title }} />;
10399
}
104-
105100
return (
106101
option?.text && (
107-
<Link className={classNames('utrecht-link', 'utrecht-link--external')} href={`/search/${option?.text}`}>
108-
{option?.text}
109-
</Link>
102+
<Link
103+
className={classNames('utrecht-link', 'utrecht-link--external')}
104+
href={`/search/${option?.text}`}
105+
dangerouslySetInnerHTML={{ __html: option?.text }}
106+
/>
110107
)
111108
);
112109
}}

0 commit comments

Comments
 (0)