Skip to content

Commit

Permalink
fix(module:back-top): fix more reliable scrolling listener (#7208)
Browse files Browse the repository at this point in the history
- close #7199
  • Loading branch information
cipchk committed Jan 17, 2022
1 parent cbfc558 commit 3bcd343
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/back-top/back-top.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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());
});
}
Expand Down
8 changes: 4 additions & 4 deletions components/back-top/back-top.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 3bcd343

Please sign in to comment.