Skip to content

Commit dce3dcd

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 16e2cf0 commit dce3dcd

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
@@ -1870,6 +1870,19 @@ describe('MatSelect', () => {
18701870
expect(requiredMarker)
18711871
.not.toBeNull(`Expected label to have an asterisk, as control was required.`);
18721872
}));
1873+
1874+
it('should propagate the value set through the `value` property to the form field',
1875+
fakeAsync(() => {
1876+
const control = fixture.componentInstance.control;
1877+
1878+
expect(control.value).toBeFalsy();
1879+
1880+
fixture.componentInstance.select.value = 'pizza-1';
1881+
fixture.detectChanges();
1882+
1883+
expect(control.value).toBe('pizza-1');
1884+
}));
1885+
18731886
});
18741887

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

src/material/select/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
432432
if (newValue !== this._value) {
433433
this.writeValue(newValue);
434434
this._value = newValue;
435+
this._onChange(newValue);
435436
}
436437
}
437438
private _value: any;

0 commit comments

Comments
 (0)