fix(select): losing focus when selecting values through binding (#7296)

Fixes an issue that caused focus to be lost after selecting a value on a select that doesn't use Angular forms.

Fixes #7092.
This commit is contained in:
Kristiyan Kostadinov
2017-09-29 22:04:13 +02:00
committed by Andrew Seguin
parent ce6cc0bb78
commit 86bea9174b
2 changed files with 19 additions and 2 deletions
+15
View File
@@ -872,6 +872,21 @@ describe('MatSelect', () => {
expect(trigger.textContent).toContain('Steak, Pizza, Sandwich');
});
it('should restore focus to the host element', () => {
const fixture = TestBed.createComponent(BasicSelectWithoutForms);
fixture.detectChanges();
fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement.click();
fixture.detectChanges();
(overlayContainerElement.querySelector('md-option') as HTMLElement).click();
fixture.detectChanges();
const select = fixture.debugElement.nativeElement.querySelector('md-select');
expect(document.activeElement).toBe(select, 'Expected trigger to be focused.');
});
});
describe('disabled behavior', () => {
+4 -2
View File
@@ -351,8 +351,10 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
@Input()
get value() { return this._value; }
set value(newValue: any) {
this.writeValue(newValue);
this._value = newValue;
if (newValue !== this._value) {
this.writeValue(newValue);
this._value = newValue;
}
}
private _value: any;