fix(autocomplete): restore focus to input when click on option (#4702)

Restores focus to the autocomplete input when an option is clicked, instead of dumping it into the body.

Fixes #4645.
This commit is contained in:
Kristiyan Kostadinov
2017-05-22 23:57:59 +02:00
committed by tinayuangao
parent b5b762abcf
commit eecf8976d6
2 changed files with 17 additions and 0 deletions
@@ -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();
+16
View File
@@ -878,6 +878,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', () => {