Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:auto-complete): can't select option when touch #2054

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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