diff --git a/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts b/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts index d42ab9158e2..fa6e1013f0c 100644 --- a/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts +++ b/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts @@ -318,7 +318,7 @@ export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnCh if (this._observer === null) { const callback = (mutationList) => { mutationList.forEach((mutation) => { - const removedNodes = new Array(... mutation.removedNodes); + const removedNodes = Array.from(mutation.removedNodes); removedNodes.forEach((n) => { if (n === this._container) { this._nodeWasRemoved = true; @@ -326,7 +326,7 @@ export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnCh } }); - const addedNodes = new Array(... mutation.addedNodes); + const addedNodes = Array.from(mutation.addedNodes); addedNodes.forEach((n) => { if (n === this.parentElement.firstElementChild && this._nodeWasRemoved) { this._container = this.parentElement.firstElementChild; diff --git a/projects/igniteui-angular/src/lib/grids/cell.component.ts b/projects/igniteui-angular/src/lib/grids/cell.component.ts index b839f523eed..f85e3ea7a04 100644 --- a/projects/igniteui-angular/src/lib/grids/cell.component.ts +++ b/projects/igniteui-angular/src/lib/grids/cell.component.ts @@ -267,12 +267,15 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit { */ get inEditMode(): boolean { const editableCell = this.gridAPI.get_cell_inEditMode(this.gridID); - if (editableCell) { - return this.cellID.rowID === editableCell.cellID.rowID && - this.cellID.columnID === editableCell.cellID.columnID; - } else { - return false; + const result = editableCell ? this.cellID.rowID === editableCell.cellID.rowID && + this.cellID.columnID === editableCell.cellID.columnID : false; + + if (result && !this._inEditMode && this.highlight && this.grid.lastSearchInfo.searchText) { + this.highlight.observe(); } + this._inEditMode = result; + + return result; } /** @@ -289,9 +292,6 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit { if (this.column.editable && value) { this.focused = true; this.gridAPI.set_cell_inEditMode(this.gridID, this); - if (this.highlight && this.grid.lastSearchInfo.searchText) { - this.highlight.observe(); - } this.editValue = this.value; } else { this.gridAPI.escape_editMode(this.gridID, this.cellID); @@ -498,6 +498,7 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit { private cellSelectionID: string; private prevCellSelectionID: string; private previousCellEditMode = false; + private _inEditMode: boolean; constructor( public gridAPI: GridBaseAPIService, diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid.search.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/grid.search.spec.ts index f3bada047db..5f38065840e 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/grid.search.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/grid/grid.search.spec.ts @@ -714,8 +714,7 @@ describe('IgxGrid - search API', () => { expect(isInView(3, grid.rowList.first.virtDirRow.state)).toBeTruthy(); }); - it('should keep the active highlight when active cell enters and exits edit mode', () => { - pending('When the cell enters edit mode, the highlight stays and the content is doubled! Happens in tests only!'); + it('should keep the active highlight when active cell enters and exits edit mode', async () => { const rv = fix.debugElement.query(By.css(CELL_CSS_CLASS)).nativeElement; const cell = grid.getCellByColumn(0, 'ID'); const initialValue = rv.textContent; @@ -724,6 +723,7 @@ describe('IgxGrid - search API', () => { cell.column.editable = true; fix.detectChanges(); + await wait(16); grid.findNext('1'); @@ -731,6 +731,7 @@ describe('IgxGrid - search API', () => { expect(activeHighlight).not.toBeNull(); cell.inEditMode = true; + await wait(16); fix.detectChanges(); expect(cell.inEditMode).toBe(true); @@ -738,17 +739,16 @@ describe('IgxGrid - search API', () => { expect(activeHighlight).toBeNull(); cell.inEditMode = false; + await wait(16); fix.detectChanges(); - expect(rv.textContent).toBe(initialValue); + expect(rv.innerText).toBe(initialValue); expect(rv.querySelectorAll('.' + component.highlightClass).length).toBe(1); activeHighlight = rv.querySelector('.' + component.activeClass); expect(activeHighlight).not.toBeNull(); }); - it('should update highlights when a new value is entered', () => { - pending('When the cell enters edit mode, the highlight stays and the content is doubled! Happens in tests only!'); - + it('should update highlights when a new value is entered', async () => { const rv = fix.debugElement.query(By.css(CELL_CSS_CLASS)); const cell = grid.getCellByColumn(0, 'ID'); cell.column.editable = true; @@ -774,8 +774,9 @@ describe('IgxGrid - search API', () => { cell.update(inputElem.value); fix.detectChanges(); + await wait(16); - expect(rv.nativeElement.textContent).toBe('11'); + expect(rv.nativeElement.innerText).toBe('11'); activeHighlight = rv.nativeElement.querySelector('.' + component.activeClass); const highlights = rv.nativeElement.querySelectorAll('.' + component.highlightClass); expect(highlights.length).toBe(2);