From 4da339cef19319da6ce6e890cb6279b04729bec6 Mon Sep 17 00:00:00 2001 From: sercan Date: Fri, 12 Oct 2018 23:59:03 +0300 Subject: [PATCH] (FusePerfectScrollbar) Unbind 'keydown' events of the PerfectScrollbar instances. This fixes the Angular Material inputs' high CPU usage.. The real problem is in the Angular Material library but we cannot do anything about it so we have removed the keyboard events of the PerfectScrollbar which resolves this years long issue. --- .../fuse-perfect-scrollbar.directive.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts b/src/@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts index a811991f..941c4937 100644 --- a/src/@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts +++ b/src/@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts @@ -15,7 +15,7 @@ export class FusePerfectScrollbarDirective implements AfterViewInit, OnDestroy { isInitialized: boolean; isMobile: boolean; - ps: PerfectScrollbar; + ps: PerfectScrollbar | any; // Private private _enabled: boolean | ''; @@ -200,6 +200,19 @@ export class FusePerfectScrollbarDirective implements AfterViewInit, OnDestroy this.ps = new PerfectScrollbar(this.elementRef.nativeElement, { ...this.fusePerfectScrollbarOptions }); + + // Unbind 'keydown' events of PerfectScrollbar since it causes an extremely + // high CPU usage on Angular Material inputs. + // Loop through all the event elements of this PerfectScrollbar instance + this.ps.event.eventElements.forEach((eventElement) => { + + // If we hit to the element with a 'keydown' event... + if ( typeof eventElement.handlers['keydown'] !== 'undefined' ) + { + // Unbind it + eventElement.element.removeEventListener('keydown', eventElement.handlers['keydown'][0]); + } + }); } /**