Skip to content

Commit

Permalink
fix(module:select): fix select scroll bottom not emit with search (#4272
Browse files Browse the repository at this point in the history
)

close #3777
  • Loading branch information
vthinkxie committed Oct 11, 2019
1 parent c7d90b7 commit e9c5541
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions components/select/nz-option-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Expand All @@ -24,7 +25,7 @@ import {
ViewEncapsulation
} from '@angular/core';
import { fromEvent, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { filter, map, pairwise, takeUntil } from 'rxjs/operators';
import { NzOptionGroupComponent } from './nz-option-group.component';
import { NzOptionLiComponent } from './nz-option-li.component';
import { NzOptionComponent } from './nz-option.component';
Expand All @@ -38,7 +39,7 @@ import { NzSelectService } from './nz-select.service';
preserveWhitespaces: false,
templateUrl: './nz-option-container.component.html'
})
export class NzOptionContainerComponent implements OnDestroy, OnInit {
export class NzOptionContainerComponent implements OnDestroy, OnInit, AfterViewInit {
private destroy$ = new Subject();
private lastScrollTop = 0;
@ViewChildren(NzOptionLiComponent) listOfNzOptionLiComponent: QueryList<NzOptionLiComponent>;
Expand All @@ -54,11 +55,10 @@ export class NzOptionContainerComponent implements OnDestroy, OnInit {
const targetOption = this.listOfNzOptionLiComponent.find(o =>
this.nzSelectService.compareWith(o.nzOption.nzValue, option.nzValue)
);
/* tslint:disable:no-any */
// tslint:disable:no-any
if (targetOption && targetOption.el && (targetOption.el as any).scrollIntoViewIfNeeded) {
(targetOption.el as any).scrollIntoViewIfNeeded(false);
}
/* tslint:enable:no-any */
}
});
}
Expand Down Expand Up @@ -98,6 +98,17 @@ export class NzOptionContainerComponent implements OnDestroy, OnInit {
});
}

ngAfterViewInit(): void {
this.listOfNzOptionLiComponent.changes
.pipe(
map(list => list.length),
pairwise(),
filter(([before, after]) => after < before),
takeUntil(this.destroy$)
)
.subscribe(() => (this.lastScrollTop = 0));
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
Expand Down

0 comments on commit e9c5541

Please sign in to comment.