Skip to content

Commit 0770054

Browse files
committed
fix(select): value set through property not being propagated to value accessor
Fixes values set through the `value` property not being propagated to the `value` in the `ControlValueAccessor`. Fixes #10214.
1 parent b60e070 commit 0770054

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/material/select/select.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,19 @@ describe('MatSelect', () => {
17931793
expect(requiredMarker)
17941794
.not.toBeNull(`Expected label to have an asterisk, as control was required.`);
17951795
}));
1796+
1797+
it('should propagate the value set through the `value` property to the form field',
1798+
fakeAsync(() => {
1799+
const control = fixture.componentInstance.control;
1800+
1801+
expect(control.value).toBeFalsy();
1802+
1803+
fixture.componentInstance.select.value = 'pizza-1';
1804+
fixture.detectChanges();
1805+
1806+
expect(control.value).toBe('pizza-1');
1807+
}));
1808+
17961809
});
17971810

17981811
describe('disabled behavior', () => {

src/material/select/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
413413
if (newValue !== this._value) {
414414
this.writeValue(newValue);
415415
this._value = newValue;
416+
this._onChange(newValue);
416417
}
417418
}
418419
private _value: any;

0 commit comments

Comments
 (0)