diff --git a/projects/igniteui-angular/src/lib/grids/cell.component.ts b/projects/igniteui-angular/src/lib/grids/cell.component.ts index 2b4d7b731d4..b839f523eed 100644 --- a/projects/igniteui-angular/src/lib/grids/cell.component.ts +++ b/projects/igniteui-angular/src/lib/grids/cell.component.ts @@ -287,6 +287,7 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit { return; } 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(); @@ -522,6 +523,10 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit { this.selected = true; if (fireFocus) { this.nativeElement.focus(); + } else { + if (!this.focused) { + this.focused = this.nativeElement === document.activeElement; + } } this.grid.onSelection.emit({ cell: this, event }); } @@ -826,8 +831,8 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit { } public onKeydownExitEditMode(event) { - if (this.column.editable) { - const editableCell = this.gridAPI.get_cell_inEditMode(this.gridID); + const editableCell = this.gridAPI.get_cell_inEditMode(this.gridID); + if (this.column.editable && editableCell) { const args: IGridEditEventArgs = { cellID: editableCell.cellID, rowID: editableCell.cellID.rowID, diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts index 075c6017f93..607807c2a7b 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts @@ -1794,11 +1794,12 @@ describe('IgxGrid Component Tests', () => { const targetCell = grid.getCellByColumn(0, 'ProductName'); targetCell.onFocus({}); - tick(); + tick(100); fixture.detectChanges(); expect(grid.endRowTransaction).toHaveBeenCalledTimes(1); expect(targetCell.focused).toBeTruthy(); - expect(firstCell.focused).toBeFalsy(); + expect(targetCell.selected).toBeTruthy(); + expect(firstCell.selected).toBeFalsy(); })); });