Skip to content

Commit feea219

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 67e710c commit feea219

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/lib/select/select.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,19 @@ describe('MatSelect', () => {
14961496
expect(requiredMarker)
14971497
.not.toBeNull(`Expected label to have an asterisk, as control was required.`);
14981498
}));
1499+
1500+
it('should propagate the value set through the `value` property to the form field',
1501+
fakeAsync(() => {
1502+
const control = fixture.componentInstance.control;
1503+
1504+
expect(control.value).toBeFalsy();
1505+
1506+
fixture.componentInstance.select.value = 'pizza-1';
1507+
fixture.detectChanges();
1508+
1509+
expect(control.value).toBe('pizza-1');
1510+
}));
1511+
14991512
});
15001513

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

src/lib/select/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
397397
if (newValue !== this._value) {
398398
this.writeValue(newValue);
399399
this._value = newValue;
400+
this._onChange(newValue);
400401
}
401402
}
402403
private _value: any;

0 commit comments

Comments
 (0)