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(autocomplete): not closing when tapping away on mobile #5260

Merged
merged 1 commit into from
Jun 22, 2017
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
6 changes: 4 additions & 2 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
/** Stream of clicks outside of the autocomplete panel. */
private get _outsideClickStream(): Observable<any> {
if (this._document) {
return Observable.fromEvent(this._document, 'click').filter((event: MouseEvent) => {
return Observable.merge(
Observable.fromEvent(this._document, 'click'),
Observable.fromEvent(this._document, 'touchend')
).filter((event: MouseEvent | TouchEvent) => {
const clickTarget = event.target as HTMLElement;
const inputContainer = this._inputContainer ?
this._inputContainer._elementRef.nativeElement : null;
Expand Down Expand Up @@ -442,4 +445,3 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
}

}

16 changes: 15 additions & 1 deletion src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('MdAutocomplete', () => {
});
}));

it('should close the panel when input loses focus', async(() => {
it('should close the panel when the user clicks away', async(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();

Expand All @@ -160,6 +160,20 @@ describe('MdAutocomplete', () => {
});
}));

it('should close the panel when the user taps away on a touch device', async(() => {
dispatchFakeEvent(input, 'focus');
fixture.detectChanges();

fixture.whenStable().then(() => {
dispatchFakeEvent(document, 'touchend');

expect(fixture.componentInstance.trigger.panelOpen)
.toBe(false, `Expected tapping outside the panel to set its state to closed.`);
expect(overlayContainerElement.textContent)
.toEqual('', `Expected tapping outside the panel to close the panel.`);
});
}));

it('should close the panel when an option is clicked', async(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
Expand Down