diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index e6fc6bbe910..57e9d54b2ce 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -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', () => { diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 7e5dfacbb07..634617007a5 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -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;