@@ -127,6 +127,13 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
127
127
this . _value = newValue ;
128
128
129
129
this . _updateSelectedRadioFromValue ( ) ;
130
+ this . _checkSelectedRadioButton ( ) ;
131
+ }
132
+ }
133
+
134
+ _checkSelectedRadioButton ( ) {
135
+ if ( this . selected && ! this . _selected . checked ) {
136
+ this . _selected . checked = true ;
130
137
}
131
138
}
132
139
@@ -139,9 +146,7 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
139
146
this . _selected = selected ;
140
147
this . value = selected ? selected . value : null ;
141
148
142
- if ( selected && ! selected . checked ) {
143
- selected . checked = true ;
144
- }
149
+ this . _checkSelectedRadioButton ( ) ;
145
150
}
146
151
147
152
/**
@@ -180,14 +185,13 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
180
185
let isAlreadySelected = this . _selected != null && this . _selected . value == this . _value ;
181
186
182
187
if ( this . _radios != null && ! isAlreadySelected ) {
183
- let matchingRadio = this . _radios . filter ( radio => radio . value == this . _value ) [ 0 ] ;
184
-
185
- if ( matchingRadio ) {
186
- this . selected = matchingRadio ;
187
- } else if ( this . value == null ) {
188
- this . selected = null ;
189
- this . _radios . forEach ( radio => { radio . checked = false ; } ) ;
190
- }
188
+ this . _selected = null ;
189
+ this . _radios . forEach ( radio => {
190
+ radio . checked = this . value == radio . value ;
191
+ if ( radio . checked ) {
192
+ this . _selected = radio ;
193
+ }
194
+ } ) ;
191
195
}
192
196
}
193
197
@@ -303,19 +307,21 @@ export class MdRadioButton implements OnInit {
303
307
}
304
308
305
309
set checked ( newCheckedState : boolean ) {
306
- this . _checked = newCheckedState ;
307
-
308
- if ( newCheckedState && this . radioGroup && this . radioGroup . value != this . value ) {
309
- this . radioGroup . selected = this ;
310
- } else if ( ! newCheckedState && this . radioGroup && this . radioGroup . value == this . value ) {
311
- // When unchecking the selected radio button, update the selected radio
312
- // property on the group.
313
- this . radioGroup . selected = null ;
314
- }
310
+ if ( this . _checked != newCheckedState ) {
311
+ this . _checked = newCheckedState ;
312
+
313
+ if ( newCheckedState && this . radioGroup && this . radioGroup . value != this . value ) {
314
+ this . radioGroup . selected = this ;
315
+ } else if ( ! newCheckedState && this . radioGroup && this . radioGroup . value == this . value ) {
316
+ // When unchecking the selected radio button, update the selected radio
317
+ // property on the group.
318
+ this . radioGroup . selected = null ;
319
+ }
315
320
316
- if ( newCheckedState ) {
317
- // Notify all radio buttons with the same name to un-check.
318
- this . radioDispatcher . notify ( this . id , this . name ) ;
321
+ if ( newCheckedState ) {
322
+ // Notify all radio buttons with the same name to un-check.
323
+ this . radioDispatcher . notify ( this . id , this . name ) ;
324
+ }
319
325
}
320
326
}
321
327
@@ -327,10 +333,17 @@ export class MdRadioButton implements OnInit {
327
333
328
334
set value ( value : any ) {
329
335
if ( this . _value != value ) {
330
- if ( this . radioGroup != null && this . checked ) {
331
- this . radioGroup . value = value ;
332
- }
333
336
this . _value = value ;
337
+ if ( this . radioGroup != null ) {
338
+ if ( ! this . checked ) {
339
+ // Update checked when the value changed to match the radio group's value
340
+ this . checked = this . radioGroup . value == value ;
341
+ }
342
+ if ( this . checked ) {
343
+ this . radioGroup . selected = this ;
344
+ }
345
+ }
346
+
334
347
}
335
348
}
336
349
0 commit comments