From 18b62b1859768ebce3f07769fa924132f4bbc389 Mon Sep 17 00:00:00 2001 From: ddincheva Date: Tue, 18 Dec 2018 14:46:21 +0200 Subject: [PATCH] fix(IgxGridCell): focus input when enter cell in edit mode #2801 --- .../igniteui-angular/src/lib/grids/cell.component.ts | 9 +++++++-- .../src/lib/grids/grid/grid.component.spec.ts | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/cell.component.ts b/projects/igniteui-angular/src/lib/grids/cell.component.ts index 1d7f2a47a17..272e105a176 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(); @@ -538,6 +539,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 }); } @@ -842,8 +847,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 621c29b03ed..6d62cc0dcd1 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 @@ -1793,11 +1793,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(); })); });