11import { Injectable } from '@angular/core' ;
2- import { first } from 'rxjs/operators' ;
2+ import { first , throttleTime } from 'rxjs/operators' ;
33import { IgxForOfDirective } from '../directives/for-of/for_of.directive' ;
44import { GridType } from './common/grid.interface' ;
55import {
@@ -17,6 +17,7 @@ import { IActiveNodeChangeEventArgs } from './common/events';
1717import { IgxGridGroupByRowComponent } from './grid/groupby-row.component' ;
1818import { IMultiRowLayoutNode } from './common/types' ;
1919import { SortingDirection } from '../data-operations/sorting-strategy' ;
20+ import { animationFrameScheduler , Subject } from 'rxjs' ;
2021export 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
0 commit comments