diff --git a/src/lib/autocomplete/autocomplete-trigger.ts b/src/lib/autocomplete/autocomplete-trigger.ts index c942146da052..cb675d1fc9e3 100644 --- a/src/lib/autocomplete/autocomplete-trigger.ts +++ b/src/lib/autocomplete/autocomplete-trigger.ts @@ -339,6 +339,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { this._clearPreviousSelectedOption(event.source); this._setTriggerValue(event.source.value); this._onChange(event.source.value); + this._element.nativeElement.focus(); } this.closePanel(); diff --git a/src/lib/autocomplete/autocomplete.spec.ts b/src/lib/autocomplete/autocomplete.spec.ts index 93b7b13aa40b..aaae39963dbd 100644 --- a/src/lib/autocomplete/autocomplete.spec.ts +++ b/src/lib/autocomplete/autocomplete.spec.ts @@ -907,6 +907,22 @@ describe('MdAutocomplete', () => { }); + it('should restore focus to the input when clicking to select a value', async(() => { + fixture.componentInstance.trigger.openPanel(); + fixture.detectChanges(); + + fixture.whenStable().then(() => { + const option = overlayContainerElement.querySelector('md-option') as HTMLElement; + + // Focus the option manually since the synthetic click may not do it. + option.focus(); + option.click(); + fixture.detectChanges(); + + expect(document.activeElement).toBe(input, 'Expected focus to be restored to the input.'); + }); + })); + }); describe('Fallback positions', () => {