Skip to content

Commit

Permalink
fix(module:auto-complete): can't select option when touch (#2054)
Browse files Browse the repository at this point in the history
close #2053
  • Loading branch information
hsuanxyz authored and wen committed Aug 31, 2018
1 parent 0e64128 commit 2e8e63d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD
const clickTarget = event.target as HTMLElement;

// 确保不是点击组件自身
if (clickTarget !== this._element.nativeElement && this.panelOpen) {
if (clickTarget !== this._element.nativeElement && !this.overlayRef.overlayElement.contains(clickTarget) && this.panelOpen) {
this.closePanel();
}
});
Expand Down
24 changes: 20 additions & 4 deletions components/auto-complete/nz-autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ describe('auto-complete', () => {
.toEqual('');
}));

it('should close the panel when an option is tap', fakeAsync(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
flush();

const option = overlayContainerElement.querySelector('nz-auto-option') as HTMLElement;
dispatchFakeEvent(option, 'touchend');
dispatchFakeEvent(option, 'click');
fixture.detectChanges();

tick(500);
expect(fixture.componentInstance.trigger.panelOpen)
.toBe(false);
expect(overlayContainerElement.textContent)
.toEqual('');
}));

it('should hide the panel when the options list is empty', fakeAsync(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
Expand Down Expand Up @@ -371,7 +388,7 @@ describe('auto-complete', () => {
flush();
fixture.detectChanges();

expect(fixture.componentInstance.inputValue)
expect(fixture.componentInstance.inputControl.value)
.toEqual('Downing Street');
}));

Expand Down Expand Up @@ -402,7 +419,7 @@ describe('auto-complete', () => {
fixture.detectChanges();
flush();

expect(fixture.componentInstance.inputValue).toBe(200);
expect(fixture.componentInstance.inputControl.value).toBe(200);
}));

it('should mark the autocomplete control as touched on blur', fakeAsync(() => {
Expand Down Expand Up @@ -720,7 +737,7 @@ describe('auto-complete', () => {
fixture.detectChanges();
flush();

expect(componentInstance.inputValue)
expect(componentInstance.inputControl.value)
.toContain('Downing Street');

expect(input.value)
Expand Down Expand Up @@ -879,7 +896,6 @@ describe('auto-complete', () => {
<div>
<input class="input"
nz-input
[(ngModel)]="inputValue"
[formControl]="inputControl"
[nzAutocomplete]="auto"
(input)="onInput($event.target?.value)">
Expand Down

0 comments on commit 2e8e63d

Please sign in to comment.