Skip to content

Commit a257fde

Browse files
committed
Merge remote-tracking branch 'origin/master' into copilot/support-multiple-entry-points
2 parents 3dc4df6 + c3386b6 commit a257fde

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

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

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

332332

333333
/** Clears cell editing state */
334-
public endCellEdit() {
334+
public endCellEdit(restoreFocus: boolean = false) {
335335
this.cell = null;
336+
if (restoreFocus) {
337+
this.grid.tbody.nativeElement.focus();
338+
}
336339
}
337340

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

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

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

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

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

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

0 commit comments

Comments
 (0)