Skip to content

Commit 839cca3

Browse files
Merge pull request #16393 from IgniteUI/mkirkova/fix-16262-20.1.x
Preserve navigation when cellEdit is cancelled and editMode is set to false - 20.1.x
2 parents ad48c96 + 07b2742 commit 839cca3

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

projects/igniteui-angular/src/lib/grids/common/crud.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,11 @@ export class IgxCellCrudState {
332332

333333

334334
/** Clears cell editing state */
335-
public endCellEdit() {
335+
public endCellEdit(restoreFocus: boolean = false) {
336336
this.cell = null;
337+
if (restoreFocus) {
338+
this.grid.tbody.nativeElement.focus();
339+
}
337340
}
338341

339342
/** Returns whether the targeted cell is in edit mode */

projects/igniteui-angular/src/lib/grids/grid-public-cell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class IgxGridCell implements CellType {
188188
// TODO possibly define similar method in gridAPI, which does not emit event
189189
this.grid.crudService.enterEditMode(this);
190190
} else {
191-
this.grid.crudService.endCellEdit();
191+
this.grid.crudService.endCellEdit(true);
192192
}
193193
this.grid.notifyChanges();
194194
}

projects/igniteui-angular/src/lib/grids/grid/grid-cell-editing.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,48 @@ describe('IgxGrid - Cell Editing #grid', () => {
361361
expect(cell.editMode).toBe(false);
362362
expect(cell.value).toBe(newValue);
363363
}));
364+
365+
it('should preserve the navigation when cancel cellEdit and async set cell.editMode=false', fakeAsync(() => {
366+
grid.cellEdit.subscribe((evt: IGridEditEventArgs) => {
367+
evt.cancel = true;
368+
const rowIndex = evt.cellID.rowIndex;
369+
const field = evt.column.field;
370+
const target = grid.getCellByColumn(rowIndex, field);
371+
setTimeout(() => {
372+
target.editMode = false;
373+
}, 100);
374+
});
375+
376+
const cell = grid.gridAPI.get_cell_by_index(0, 'fullName');
377+
378+
UIInteractions.simulateDoubleClickAndSelectEvent(cell);
379+
fixture.detectChanges();
380+
tick(16);
381+
expect(cell.editMode).toBeTrue();
382+
383+
const editInput = fixture.debugElement.query(By.css('igx-grid-cell input'));
384+
if (editInput) {
385+
UIInteractions.clickAndSendInputElementValue(editInput, 'Edited');
386+
}
387+
fixture.detectChanges();
388+
389+
UIInteractions.triggerEventHandlerKeyDown('enter', gridContent);
390+
fixture.detectChanges();
391+
392+
tick(100);
393+
fixture.detectChanges();
394+
expect(cell.editMode).toBeFalse();
395+
396+
expect(document.activeElement).toBe(grid.tbody.nativeElement);
397+
398+
UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', document.activeElement as HTMLElement, true);
399+
fixture.detectChanges();
400+
401+
const nextCell = grid.getCellByColumn(0, 'age');
402+
const active = (grid as any).navigation.activeNode;
403+
expect(active.row).toBe(0);
404+
expect(active.column).toBe(nextCell.column.visibleIndex);
405+
}));
364406
});
365407

366408
describe('Scroll, pin and blur', () => {

0 commit comments

Comments
 (0)