Skip to content

Commit

Permalink
fix(module:select): fix nzOpen state when nzOnSearch trigger
Browse files Browse the repository at this point in the history
close #3626
  • Loading branch information
vthinkxie authored and vthinkxie committed Jun 22, 2019
1 parent 36db36c commit 3ca816d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
27 changes: 22 additions & 5 deletions components/core/addon/string_template_outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,30 @@ export class NzStringTemplateOutletDirective implements OnChanges {
}
}

// tslint:disable-next-line:no-any
private getType(value: string | TemplateRef<any>): 'template' | 'string' {
if (value instanceof TemplateRef) {
return 'template';
} else {
return 'string';
}
}

private shouldRecreateView(changes: SimpleChanges): boolean {
const { nzStringTemplateOutletContext, nzStringTemplateOutlet } = changes;
return (
!!nzStringTemplateOutlet ||
(nzStringTemplateOutletContext && this.hasContextShapeChanged(nzStringTemplateOutletContext))
);
let shouldOutletRecreate = false;
if (nzStringTemplateOutlet) {
if (nzStringTemplateOutlet.firstChange) {
shouldOutletRecreate = true;
} else {
const previousOutletType = this.getType(nzStringTemplateOutlet.previousValue);
const currentOutletType = this.getType(nzStringTemplateOutlet.currentValue);
shouldOutletRecreate = !(previousOutletType === 'string' && currentOutletType === 'string');
}
}
const shouldContextRecreate =
nzStringTemplateOutletContext && this.hasContextShapeChanged(nzStringTemplateOutletContext);
return shouldContextRecreate || shouldOutletRecreate;
}

private hasContextShapeChanged(ctxChange: SimpleChange): boolean {
Expand Down Expand Up @@ -102,7 +120,6 @@ export class NzStringTemplateOutletDirective implements OnChanges {

ngOnChanges(changes: SimpleChanges): void {
const recreateView = this.shouldRecreateView(changes);

if (recreateView) {
if (this.viewContainer) {
this.viewContainer.clear();
Expand Down
3 changes: 0 additions & 3 deletions components/select/nz-select-top-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export class NzSelectTopControlComponent implements OnInit, OnDestroy {
}

setInputValue(value: string): void {
/* if (this.inputElement) {
this.inputElement.nativeElement.value = value;
} */
this.inputValue = value;
this.updateWidth();
this.nzSelectService.updateSearchValue(value);
Expand Down
1 change: 1 addition & 0 deletions components/select/nz-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie
this.onTouched();
}
this.open = value;
this.nzSelectService.clearInput();
});
this.nzSelectService.check$.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.cdr.markForCheck();
Expand Down
8 changes: 2 additions & 6 deletions components/select/nz-select.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export class NzSelectService {
searchValue = '';
isShowNotFound = false;
// open
open$ = this.openRaw$.pipe(
distinctUntilChanged(),
share(),
tap(() => this.clearInput())
);
open$ = this.openRaw$.pipe(distinctUntilChanged());
activatedOption: NzOptionComponent | null;
activatedOption$ = new ReplaySubject<NzOptionComponent | null>(1);
listOfSelectedValue$ = this.listOfSelectedValueWithEmit$.pipe(map(data => data.value));
Expand Down Expand Up @@ -103,7 +99,7 @@ export class NzSelectService {
// display in top control
listOfCachedSelectedOption: NzOptionComponent[] = [];
// selected value or ViewChildren change
valueOrOption$ = combineLatest(this.listOfSelectedValue$, this.mapOfTemplateOption$).pipe(
valueOrOption$ = combineLatest([this.listOfSelectedValue$, this.mapOfTemplateOption$]).pipe(
tap(data => {
this.listOfSelectedValue = data[0];
this.listOfNzOptionComponent = data[1].listOfNzOptionComponent;
Expand Down

0 comments on commit 3ca816d

Please sign in to comment.