From c2e885d12a895f1c9a7fa5595eba5aa218981329 Mon Sep 17 00:00:00 2001 From: vthinkxie Date: Mon, 22 Apr 2019 10:00:14 +0800 Subject: [PATCH] fix(module:select): fix select search display (#3324) close #3322 --- components/select/nz-select-top-control.component.ts | 4 ++-- components/select/nz-select-top-control.spec.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/select/nz-select-top-control.component.ts b/components/select/nz-select-top-control.component.ts index 0f5e4c44919..7eeeac5370c 100644 --- a/components/select/nz-select-top-control.component.ts +++ b/components/select/nz-select-top-control.component.ts @@ -122,7 +122,7 @@ export class NzSelectTopControlComponent implements OnInit, OnDestroy { } } - removeSelectedValue(option: NzOptionComponent, e: KeyboardEvent): void { + removeSelectedValue(option: NzOptionComponent, e: MouseEvent): void { this.nzSelectService.removeValueFormSelected(option); e.stopPropagation(); } @@ -137,7 +137,7 @@ export class NzSelectTopControlComponent implements OnInit, OnDestroy { ngOnInit(): void { this.nzSelectService.open$.pipe(takeUntil(this.destroy$)).subscribe(open => { if (this.inputElement && open) { - this.inputElement.nativeElement.focus(); + setTimeout(() => this.inputElement.nativeElement.focus()); } }); this.nzSelectService.clearInput$.pipe(takeUntil(this.destroy$)).subscribe(() => { diff --git a/components/select/nz-select-top-control.spec.ts b/components/select/nz-select-top-control.spec.ts index ecb2e0b3d71..d5b572c283b 100644 --- a/components/select/nz-select-top-control.spec.ts +++ b/components/select/nz-select-top-control.spec.ts @@ -1,5 +1,5 @@ import { Component, DebugElement } from '@angular/core'; -import { fakeAsync, flush, ComponentFixture, TestBed } from '@angular/core/testing'; +import { fakeAsync, flush, tick, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { Subject } from 'rxjs'; @@ -128,7 +128,7 @@ describe('nz-select top control', () => { expect(tcComponent.selectedValueStyle.display).toBe('block'); expect(tcComponent.selectedValueStyle.opacity).toBe('0.4'); }); - it('should open focus', () => { + it('should open focus', fakeAsync(() => { fixture.detectChanges(); expect(tc.nativeElement.querySelector('.ant-select-search__field') === document.activeElement).toBeFalsy(); // @ts-ignore @@ -138,8 +138,10 @@ describe('nz-select top control', () => { // @ts-ignore nzSelectService.open$.next(true); fixture.detectChanges(); + tick(); + fixture.detectChanges(); expect(tc.nativeElement.querySelector('.ant-select-search__field') === document.activeElement).toBeTruthy(); - }); + })); it('should destroy piped', () => { fixture.detectChanges(); // @ts-ignore