From 3bcd343e38aefc35af1c2386a539d19a1d0ca279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Mon, 17 Jan 2022 11:03:03 +0800 Subject: [PATCH] fix(module:back-top): fix more reliable scrolling listener (#7208) - close #7199 --- components/back-top/back-top.component.ts | 4 ++-- components/back-top/back-top.spec.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/back-top/back-top.component.ts b/components/back-top/back-top.component.ts index 41c0b67b3d7..c0749d91a52 100644 --- a/components/back-top/back-top.component.ts +++ b/components/back-top/back-top.component.ts @@ -24,7 +24,7 @@ import { ViewEncapsulation } from '@angular/core'; import { fromEvent, Subject } from 'rxjs'; -import { takeUntil, throttleTime } from 'rxjs/operators'; +import { debounceTime, takeUntil } from 'rxjs/operators'; import { fadeMotion } from 'ng-zorro-antd/core/animation'; import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config'; @@ -127,7 +127,7 @@ export class NzBackTopComponent implements OnInit, OnDestroy, OnChanges { this.handleScroll(); this.zone.runOutsideAngular(() => { fromEvent(this.getTarget(), 'scroll') - .pipe(throttleTime(50), takeUntil(this.scrollListenerDestroy$)) + .pipe(debounceTime(50), takeUntil(this.scrollListenerDestroy$)) .subscribe(() => this.handleScroll()); }); } diff --git a/components/back-top/back-top.spec.ts b/components/back-top/back-top.spec.ts index d89fa4d9c64..85a8ed66960 100644 --- a/components/back-top/back-top.spec.ts +++ b/components/back-top/back-top.spec.ts @@ -162,10 +162,10 @@ describe('Component:nz-back-top', () => { })); it('element scroll shows the button', fakeAsync(() => { - const throttleTime = 50; + const time = 50; componentObject.scrollTo(fakeTarget, defaultVisibilityHeight + 1); - tick(throttleTime + 1); + tick(time + 1); fixture.detectChanges(); expect(componentObject.backTopButton() === null).toBe(false); @@ -174,10 +174,10 @@ describe('Component:nz-back-top', () => { it('element (use string id) scroll shows the button', fakeAsync(() => { component.nzTarget = '#fakeTarget'; - const throttleTime = 50; + const time = 50; componentObject.scrollTo(fakeTarget, defaultVisibilityHeight + 1); - tick(throttleTime + 1); + tick(time + 1); fixture.detectChanges(); expect(componentObject.backTopButton() === null).toBe(false);