From 594d2169a0a06f7a7a4d445926cc4fd70984e1a2 Mon Sep 17 00:00:00 2001 From: Wendell Date: Wed, 8 Aug 2018 17:55:05 +0800 Subject: [PATCH] fix(module:select): fix input not blur after user hits enter key close #1940 --- .vscode/launch.json | 12 ------------ components/select/nz-select.component.ts | 1 + components/select/nz-select.spec.ts | 12 ++++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 12513a1b076..00000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "chrome", - "request": "launch", - "name": "Chrome", - "url": "http://localhost:9876", - "webRoot": "${workspaceRoot}" - } - ] -} \ No newline at end of file diff --git a/components/select/nz-select.component.ts b/components/select/nz-select.component.ts index cf3f062fd11..bb23d969d77 100644 --- a/components/select/nz-select.component.ts +++ b/components/select/nz-select.component.ts @@ -298,6 +298,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie this.onTouched(); this.nzOpen = false; this.nzOpenChange.emit(this.nzOpen); + this.blur(); } } diff --git a/components/select/nz-select.spec.ts b/components/select/nz-select.spec.ts index df7f12027c9..a360a9a8348 100644 --- a/components/select/nz-select.spec.ts +++ b/components/select/nz-select.spec.ts @@ -192,6 +192,18 @@ describe('nz-select component', () => { fixture.detectChanges(); expect(testComponent.onSearch).toHaveBeenCalledTimes(1); }); + it('should blur after user hits enter key in single mode', () => { + const spy = spyOn(testComponent.nzSelectComponent, 'blur'); + testComponent.showSearch = true; + select.nativeElement.click(); + fixture.detectChanges(); + dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', 40); + fixture.detectChanges(); + expect(spy).not.toHaveBeenCalled(); + dispatchKeyboardEvent(select.nativeElement.querySelector('.ant-select-selection'), 'keydown', 13); + fixture.detectChanges(); + expect(spy).toHaveBeenCalled(); + }); }); describe('tags', () => { let fixture;