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