Skip to content
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