Skip to content

Commit

Permalink
fix(js): change highlighted element key to index
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Feb 9, 2021
1 parent c442884 commit d4d0348
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/autocomplete-js/src/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ export function highlightHit<TItem extends Hit<{}>>({
tagName = 'mark',
createElement = preactCreateElement,
}: HighlightItemParams<TItem>) {
return parseAlgoliaHitHighlight<TItem>({ hit, attribute }).map((x) =>
x.isHighlighted
? createElement(tagName, { key: x.value, children: x.value })
: x.value
return parseAlgoliaHitHighlight<TItem>({ hit, attribute }).map((x, index) =>
x.isHighlighted ? createElement(tagName, { key: index }, x.value) : x.value
);
}

Expand All @@ -43,10 +41,11 @@ export function reverseHighlightHit<TItem extends Hit<{}>>({
tagName = 'mark',
createElement = preactCreateElement,
}: HighlightItemParams<TItem>) {
return parseAlgoliaHitReverseHighlight<TItem>({ hit, attribute }).map((x) =>
x.isHighlighted
? createElement(tagName, { key: x.value, children: x.value })
: x.value
return parseAlgoliaHitReverseHighlight<TItem>({
hit,
attribute,
}).map((x, index) =>
x.isHighlighted ? createElement(tagName, { key: index }, x.value) : x.value
);
}

Expand All @@ -59,10 +58,8 @@ export function snippetHit<TItem extends Hit<{}>>({
tagName = 'mark',
createElement = preactCreateElement,
}: HighlightItemParams<TItem>) {
return parseAlgoliaHitSnippet<TItem>({ hit, attribute }).map((x) =>
x.isHighlighted
? createElement(tagName, { key: x.value, children: x.value })
: x.value
return parseAlgoliaHitSnippet<TItem>({ hit, attribute }).map((x, index) =>
x.isHighlighted ? createElement(tagName, { key: index }, x.value) : x.value
);
}

Expand All @@ -77,9 +74,10 @@ export function reverseSnippetHit<TItem extends Hit<{}>>({
tagName = 'mark',
createElement = preactCreateElement,
}: HighlightItemParams<TItem>) {
return parseAlgoliaHitReverseSnippet<TItem>({ hit, attribute }).map((x) =>
x.isHighlighted
? createElement(tagName, { key: x.value, children: x.value })
: x.value
return parseAlgoliaHitReverseSnippet<TItem>({
hit,
attribute,
}).map((x, index) =>
x.isHighlighted ? createElement(tagName, { key: index }, x.value) : x.value
);
}

0 comments on commit d4d0348

Please sign in to comment.