Skip to content

Commit ecbcd71

Browse files
DiyanDimitrovgedinakovaigdmdimitrovkdinev
authored
fix(highlight): skip active highlight if index is -1 (#10030)
* fix(highlight): skip active highlight if index is -1 * test(highlight): add activateIfNecessary test Co-authored-by: Galina Edinakova <[email protected]> Co-authored-by: igdmdimitrov <[email protected]> Co-authored-by: Konstantin Dinev <[email protected]>
1 parent 5659a2e commit ecbcd71

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ describe('IgxHighlight', () => {
286286
expect(spans.length).toBe(4);
287287
expect(activeSpans.length).toBe(1);
288288
});
289+
290+
it('Should not throw error when active highlight is not set', () => {
291+
const fix = TestBed.createComponent(HighlightLoremIpsumComponent);
292+
fix.detectChanges();
293+
294+
const component: HighlightLoremIpsumComponent = fix.debugElement.componentInstance;
295+
component.highlight.row = undefined;
296+
component.highlight.column = undefined;
297+
component.highlightText('a');
298+
299+
expect(() => component.highlight.activateIfNecessary()).not.toThrowError();
300+
});
301+
289302
});
290303

291304
@Component({

projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke
340340
public activateIfNecessary(): void {
341341
const group = IgxTextHighlightDirective.highlightGroupsMap.get(this.groupName);
342342

343-
if (group.column === this.column && group.row === this.row && compareMaps(this.metadata, group.metadata)) {
343+
if (group.index >= 0 && group.column === this.column && group.row === this.row && compareMaps(this.metadata, group.metadata)) {
344344
this.activate(group.index);
345345
}
346346
}

0 commit comments

Comments
 (0)