Skip to content

Commit

Permalink
perf(module:anchor): mark scroll listener as passive (#7330)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Apr 20, 2022
1 parent ffef342 commit aab060f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/anchor/anchor.component.ts
Expand Up @@ -3,7 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Platform } from '@angular/cdk/platform';
import { normalizePassiveListenerOptions, Platform } from '@angular/cdk/platform';
import { DOCUMENT } from '@angular/common';
import {
AfterViewInit,
Expand Down Expand Up @@ -42,6 +42,8 @@ interface Section {
const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'anchor';
const sharpMatcherRegx = /#([^#]+)$/;

const passiveEventListenerOptions = normalizePassiveListenerOptions({ passive: true });

@Component({
selector: 'nz-anchor',
exportAs: 'nzAnchor',
Expand Down Expand Up @@ -143,7 +145,7 @@ export class NzAnchorComponent implements OnDestroy, AfterViewInit, OnChanges {
}
this.destroy$.next();
this.zone.runOutsideAngular(() => {
fromEvent(this.getContainer(), 'scroll')
fromEvent(this.getContainer(), 'scroll', <AddEventListenerOptions>passiveEventListenerOptions)
.pipe(throttleTime(50), takeUntil(this.destroy$))
.subscribe(() => this.handleScroll());
});
Expand Down

0 comments on commit aab060f

Please sign in to comment.