File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -264,13 +264,18 @@ export class TypeaheadContainerComponent implements OnDestroy {
264
264
? latinize ( itemStr )
265
265
: itemStr ) . toLowerCase ( ) ;
266
266
let startIdx : number ;
267
- let tokenLen : number ;
267
+ let tokenLen = 0 ;
268
268
// Replaces the capture string with the same string inside of a "strong" tag
269
269
if ( typeof query === 'object' ) {
270
270
const queryLen : number = query . length ;
271
+ let indexOfTrimmedMatch :number ;
271
272
for ( let i = 0 ; i < queryLen ; i += 1 ) {
272
273
// 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 ;
274
279
tokenLen = query [ i ] . length ;
275
280
if ( startIdx >= 0 && tokenLen > 0 ) {
276
281
itemStr =
You can’t perform that action at this time.
0 commit comments