Skip to content

Commit 1c1dc75

Browse files
authored
fix(IgxGrid): Add notifier for repeating keydown. Limit change detect… (#16304)
1 parent 7f538ff commit 1c1dc75

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { first } from 'rxjs/operators';
2+
import { first, throttleTime } from 'rxjs/operators';
33
import { IgxForOfDirective } from '../directives/for-of/for_of.directive';
44
import { GridType } from './common/grid.interface';
55
import {
@@ -17,6 +17,7 @@ import { IActiveNodeChangeEventArgs } from './common/events';
1717
import { IgxGridGroupByRowComponent } from './grid/groupby-row.component';
1818
import { IMultiRowLayoutNode } from './common/types';
1919
import { SortingDirection } from '../data-operations/sorting-strategy';
20+
import { animationFrameScheduler, Subject } from 'rxjs';
2021
export interface ColumnGroupsCache {
2122
level: number;
2223
visibleIndex: number;
@@ -37,6 +38,7 @@ export class IgxGridNavigationService {
3738
public _activeNode: IActiveNode = {} as IActiveNode;
3839
public lastActiveNode: IActiveNode = {} as IActiveNode;
3940
protected pendingNavigation = false;
41+
protected keydownNotify = new Subject<KeyboardEvent>();
4042

4143
public get activeNode() {
4244
return this._activeNode;
@@ -46,7 +48,15 @@ export class IgxGridNavigationService {
4648
this._activeNode = value;
4749
}
4850

49-
constructor(protected platform: PlatformUtil) { }
51+
constructor(protected platform: PlatformUtil) {
52+
this.keydownNotify.pipe(
53+
throttleTime(30, animationFrameScheduler),
54+
)
55+
.subscribe((event: KeyboardEvent) => {
56+
this.dispatchEvent(event);
57+
});
58+
59+
}
5060

5161
public handleNavigation(event: KeyboardEvent) {
5262
const key = event.key.toLowerCase();
@@ -60,7 +70,7 @@ export class IgxGridNavigationService {
6070
event.preventDefault();
6171
}
6272
if (event.repeat) {
63-
setTimeout(() => this.dispatchEvent(event), 1);
73+
this.keydownNotify.next(event);
6474
} else {
6575
this.dispatchEvent(event);
6676
}
@@ -96,10 +106,8 @@ export class IgxGridNavigationService {
96106
event.preventDefault();
97107
this.navigateInBody(position.rowIndex, position.colIndex, (obj) => {
98108
obj.target.activate(event);
99-
this.grid.cdr.detectChanges();
100109
});
101110
}
102-
this.grid.cdr.detectChanges();
103111
}
104112

105113
public summaryNav(event: KeyboardEvent) {
@@ -145,7 +153,6 @@ export class IgxGridNavigationService {
145153
this.grid.clearCellSelection();
146154
this.grid.navigateTo(this.activeNode.row, this.activeNode.column, (obj) => {
147155
obj.target?.activate(event);
148-
this.grid.cdr.detectChanges();
149156
});
150157
} else {
151158
if (hasLastActiveNode && !this.grid.selectionService.selected(this.lastActiveNode)) {
@@ -598,7 +605,6 @@ export class IgxGridNavigationService {
598605

599606
this.navigateInBody(next.rowIndex, next.visibleColumnIndex, (obj) => {
600607
obj.target.activate(event);
601-
this.grid.cdr.detectChanges();
602608
});
603609
}
604610

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ describe('IgxGrid - Row Editing #grid', () => {
617617
// let cellDebug;
618618
UIInteractions.simulateDoubleClickAndSelectEvent(cellElem);
619619
fix.detectChanges();
620+
await wait(DEBOUNCETIME);
621+
fix.detectChanges();
620622

621623
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent, false, true);
622624
await wait(DEBOUNCETIME);
@@ -977,11 +979,11 @@ describe('IgxGrid - Row Editing #grid', () => {
977979
fix.detectChanges();
978980

979981
const keyDonwSpy = spyOn(grid.gridKeydown, 'emit');
980-
const detectChangesSpy = spyOn(grid.cdr, 'detectChanges').and.callThrough();
981982

982983
UIInteractions.simulateDoubleClickAndSelectEvent(targetCell);
983984
fix.detectChanges();
984985

986+
const detectChangesSpy = spyOn(grid.cdr, 'detectChanges').and.callThrough();
985987
const cellElem = fix.debugElement.query(By.css(CELL_CLASS));
986988
const input = cellElem.query(By.css('input'));
987989

projects/igniteui-angular/src/lib/test-utils/helper-utils.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export let gridsubscriptions: Subscription [] = [];
2828
export const setupGridScrollDetection = (fixture: ComponentFixture<any>, grid: GridType) => {
2929
gridsubscriptions.push(grid.verticalScrollContainer.chunkLoad.subscribe(() => fixture.detectChanges()));
3030
gridsubscriptions.push(grid.parentVirtDir.chunkLoad.subscribe(() => fixture.detectChanges()));
31+
gridsubscriptions.push(grid.activeNodeChange.subscribe(() => grid.cdr.detectChanges()));
32+
gridsubscriptions.push(grid.selected.subscribe(() => grid.cdr.detectChanges()));
3133
};
3234

3335
export const setupHierarchicalGridScrollDetection = (fixture: ComponentFixture<any>, hierarchicalGrid: IgxHierarchicalGridComponent) => {

src/app/grid-performance/grid-performance.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h4 class="sample-title"> Fixed Size Rows</h4>
88
</igx-grid-toolbar-actions>
99
</igx-grid-toolbar>
1010
@for (c of columns; track c) {
11-
<igx-column width='auto' [sortable]="true" [filterable]="true" [resizable]="true" [field]="c.field" [header]="c.field">
11+
<igx-column width='auto' [editable]="true" [sortable]="true" [filterable]="true" [resizable]="true" [field]="c.field" [header]="c.field">
1212
</igx-column>
1313
}
1414
</igx-grid>

0 commit comments

Comments
 (0)