Skip to content

Commit 0866e6a

Browse files
MKirovaMKirova
authored andcommitted
fix(IgxGrid): Add notifier for repeating keydown. Limit change detection.
1 parent efbdca9 commit 0866e6a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
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

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)