Skip to content

Commit f41fa8c

Browse files
devversiontinayuangao
authored andcommitted
fix(radio): coerce checked input binding (#8556)
* Coerces the `checked` input binding for radio-buttons. This allows developers to specify the initial checked radio-button from the template.
1 parent 53c94c7 commit f41fa8c

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/demo-app/radio/radio-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1>Basic Example</h1>
22
<section class="demo-section">
3-
<mat-radio-button name="group1">Option 1</mat-radio-button>
3+
<mat-radio-button name="group1" checked>Option 1</mat-radio-button>
44
<mat-radio-button name="group1">Option 2</mat-radio-button>
55
<mat-radio-button name="group1" disabled="true">Option 3 (disabled)</mat-radio-button>
66
</section>

src/lib/radio/radio.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,10 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
365365

366366
/** Whether this radio button is checked. */
367367
@Input()
368-
get checked(): boolean {
369-
return this._checked;
370-
}
368+
get checked(): boolean { return this._checked; }
369+
set checked(value: boolean) {
370+
const newCheckedState = coerceBooleanProperty(value);
371371

372-
set checked(newCheckedState: boolean) {
373372
if (this._checked != newCheckedState) {
374373
this._checked = newCheckedState;
375374

0 commit comments

Comments
 (0)