mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
tinayuangao
parent
b5b762abcf
commit
eecf8976d6
@@ -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();
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user