Skip to content

Commit 3bcd343

Browse files
authored
fix(module:back-top): fix more reliable scrolling listener (#7208)
- close #7199
1 parent cbfc558 commit 3bcd343

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

components/back-top/back-top.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
ViewEncapsulation
2525
} from '@angular/core';
2626
import { fromEvent, Subject } from 'rxjs';
27-
import { takeUntil, throttleTime } from 'rxjs/operators';
27+
import { debounceTime, takeUntil } from 'rxjs/operators';
2828

2929
import { fadeMotion } from 'ng-zorro-antd/core/animation';
3030
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
@@ -127,7 +127,7 @@ export class NzBackTopComponent implements OnInit, OnDestroy, OnChanges {
127127
this.handleScroll();
128128
this.zone.runOutsideAngular(() => {
129129
fromEvent(this.getTarget(), 'scroll')
130-
.pipe(throttleTime(50), takeUntil(this.scrollListenerDestroy$))
130+
.pipe(debounceTime(50), takeUntil(this.scrollListenerDestroy$))
131131
.subscribe(() => this.handleScroll());
132132
});
133133
}

components/back-top/back-top.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ describe('Component:nz-back-top', () => {
162162
}));
163163

164164
it('element scroll shows the button', fakeAsync(() => {
165-
const throttleTime = 50;
165+
const time = 50;
166166

167167
componentObject.scrollTo(fakeTarget, defaultVisibilityHeight + 1);
168-
tick(throttleTime + 1);
168+
tick(time + 1);
169169
fixture.detectChanges();
170170

171171
expect(componentObject.backTopButton() === null).toBe(false);
@@ -174,10 +174,10 @@ describe('Component:nz-back-top', () => {
174174
it('element (use string id) scroll shows the button', fakeAsync(() => {
175175
component.nzTarget = '#fakeTarget';
176176

177-
const throttleTime = 50;
177+
const time = 50;
178178

179179
componentObject.scrollTo(fakeTarget, defaultVisibilityHeight + 1);
180-
tick(throttleTime + 1);
180+
tick(time + 1);
181181
fixture.detectChanges();
182182

183183
expect(componentObject.backTopButton() === null).toBe(false);

0 commit comments

Comments
 (0)