Skip to content

Commit

Permalink
fix: search highlight (#2410)
Browse files Browse the repository at this point in the history
* fix: search highlight

* wip
  • Loading branch information
Paul-Bob committed Jan 25, 2024
1 parent 05390b8 commit 15970dc
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions app/javascript/js/controllers/search_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Mousetrap from 'mousetrap'
import { Controller } from '@hotwired/stimulus'
import { Turbo } from '@hotwired/turbo-rails'
import { autocomplete } from '@algolia/autocomplete-js'
import { sanitize } from 'dompurify'
import URI from 'urijs'
import debouncePromise from '../helpers/debounce_promise'

Expand All @@ -21,11 +22,11 @@ export default class extends Controller {
'visibleLabel',
'clearValue',
'clearButton',
];
]

debouncedFetch = debouncePromise(fetch, this.searchDebounce);
debouncedFetch = debouncePromise(fetch, this.searchDebounce)

destroyMethod;
destroyMethod

get dataset() {
return this.autocompleteTarget.dataset
Expand Down Expand Up @@ -157,15 +158,29 @@ export default class extends Controller {
)
}

const labelChildren = [item._label]
const label = sanitize(item._label)

const labelChildren = [
createElement(
'div',
{
dangerouslySetInnerHTML: { __html: label },
},
label,
),
]

if (item._description) {
const description = sanitize(item._description)

labelChildren.push(
createElement(
'div',
{
class: 'aa-ItemDescription',
dangerouslySetInnerHTML: { __html: description },
},
item._description,
description,
),
)
}
Expand Down

0 comments on commit 15970dc

Please sign in to comment.