Skip to content

Commit 3bf712d

Browse files
author
udayk
committed
fix(Typeahead) Typeahead highlight displays <strong> tag when empty spaces added at the end of query and does not escape html tags
1 parent 7bea10f commit 3bf712d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/typeahead/typeahead-container.component.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,18 @@ export class TypeaheadContainerComponent implements OnDestroy {
264264
? latinize(itemStr)
265265
: itemStr).toLowerCase();
266266
let startIdx: number;
267-
let tokenLen: number;
267+
let tokenLen = 0;
268268
// Replaces the capture string with the same string inside of a "strong" tag
269269
if (typeof query === 'object') {
270270
const queryLen: number = query.length;
271+
let indexOfTrimmedMatch:number;
271272
for (let i = 0; i < queryLen; i += 1) {
272273
// query[i] is already latinized and lower case
273-
startIdx = itemStrHelper.indexOf(query[i]);
274+
// When user type empty string as query, it always taking first index(0) instead of space after the query word.
275+
// as result it adding the html markup, so to solve this issue we are trimming the match and find the index.
276+
// If it is valid index adding token lenth to it
277+
indexOfTrimmedMatch = itemStrHelper.trim().indexOf(query[i]);
278+
startIdx = query[i].trim() ? itemStrHelper.indexOf(query[i]) : indexOfTrimmedMatch >= 0 ? indexOfTrimmedMatch + tokenLen : -1;
274279
tokenLen = query[i].length;
275280
if (startIdx >= 0 && tokenLen > 0) {
276281
itemStr =

0 commit comments

Comments
 (0)