Skip to content

Commit 2bf675e

Browse files
damyanpetevrkaraivanovddincheva
authored
fix(grid): nav service cdr & event emit while row edit (#14735)
* test(grid): add test for row edit nav service handling/events * fix(grid): nav service cdr & event emit while row edit * fix(grid): nav service cdr & event emit while row edit --------- Co-authored-by: Radoslav Karaivanov <[email protected]> Co-authored-by: Desislava Dincheva <[email protected]>
1 parent 07037b2 commit 2bf675e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

projects/igniteui-angular/src/lib/grids/grid-navigation.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ export class IgxGridNavigationService {
6868

6969
public dispatchEvent(event: KeyboardEvent) {
7070
const key = event.key.toLowerCase();
71-
if (!this.activeNode || !(SUPPORTED_KEYS.has(key) || (key === 'tab' && this.grid.crudService.cell)) &&
72-
!this.grid.crudService.rowEditingBlocked && !this.grid.crudService.rowInEditMode) {
71+
const cellOrRowInEdit = this.grid.crudService.cell || this.grid.crudService.row;
72+
if (!this.activeNode || !(SUPPORTED_KEYS.has(key) || (key === 'tab' && cellOrRowInEdit))) {
7373
return;
7474
}
7575
const shift = event.shiftKey;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,33 @@ describe('IgxGrid - Row Editing #grid', () => {
971971
expect(targetCell.active).toBeTruthy();
972972
}));
973973

974+
it(`Should not detectChanges & emit Grid.keyDown (navigation service) while editing`, () => {
975+
targetCell = grid.gridAPI.get_cell_by_index(0, 'Downloads');
976+
977+
fix.detectChanges();
978+
979+
const keyDonwSpy = spyOn(grid.gridKeydown, 'emit');
980+
const detectChangesSpy = spyOn(grid.cdr, 'detectChanges').and.callThrough();
981+
982+
UIInteractions.simulateDoubleClickAndSelectEvent(targetCell);
983+
fix.detectChanges();
984+
985+
const cellElem = fix.debugElement.query(By.css(CELL_CLASS));
986+
const input = cellElem.query(By.css('input'));
987+
988+
// change first editable cell value
989+
UIInteractions.triggerKeyDownEvtUponElem('1', input.nativeElement, true);
990+
UIInteractions.setInputElementValue(input, '1');
991+
992+
UIInteractions.triggerKeyDownEvtUponElem('2', input.nativeElement, true);
993+
UIInteractions.setInputElementValue(input, '12');
994+
fix.detectChanges();
995+
996+
expect(targetCell.editValue).toBe(12);
997+
998+
expect(keyDonwSpy).not.toHaveBeenCalled();
999+
expect(detectChangesSpy).toHaveBeenCalledTimes(0);
1000+
});
9741001
});
9751002

9761003
describe('Exit row editing', () => {

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-navigation.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
1111

1212
public override dispatchEvent(event: KeyboardEvent) {
1313
const key = event.key.toLowerCase();
14-
if (!this.activeNode || !(SUPPORTED_KEYS.has(key) || (key === 'tab' && this.grid.crudService.cell)) &&
15-
!this.grid.crudService.rowEditingBlocked && !this.grid.crudService.rowInEditMode) {
14+
const cellOrRowInEdit = this.grid.crudService.cell || this.grid.crudService.row;
15+
if (!this.activeNode || !(SUPPORTED_KEYS.has(key) || (key === 'tab' && cellOrRowInEdit))) {
1616
return;
1717
}
1818

0 commit comments

Comments
 (0)