1
1
import {
2
2
AfterContentInit ,
3
+ ChangeDetectionStrategy ,
4
+ ChangeDetectorRef ,
3
5
Component ,
4
6
ContentChildren ,
5
7
Directive ,
@@ -125,14 +127,31 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
125
127
}
126
128
127
129
/** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
128
- @Input ( ) labelPosition : 'before' | 'after' = 'after' ;
130
+ _labelPosition : 'before' | 'after' = 'after' ;
131
+ @Input ( )
132
+ get labelPosition ( ) : 'before' | 'after' {
133
+ return this . _labelPosition ;
134
+ }
135
+ set labelPosition ( v : 'before' | 'after' ) {
136
+ this . _labelPosition = v
137
+ if ( this . _radios ) {
138
+ this . _radios . forEach ( ( radio ) => {
139
+ radio . labelPosition = this . _labelPosition ;
140
+ } ) ;
141
+ }
142
+ }
129
143
130
144
/** Whether the radio button is disabled. */
131
145
@Input ( )
132
146
get disabled ( ) : boolean { return this . _disabled ; }
133
147
set disabled ( value ) {
134
148
// The presence of *any* disabled value makes the component disabled, *except* for false.
135
149
this . _disabled = ( value != null && value !== false ) ? true : null ;
150
+ if ( this . _radios ) {
151
+ this . _radios . forEach ( ( radio ) => {
152
+ radio . disabled = this . _disabled ;
153
+ } )
154
+ }
136
155
}
137
156
138
157
/** Value of the radio button. */
@@ -261,7 +280,8 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
261
280
selector : 'md-radio-button, mat-radio-button' ,
262
281
templateUrl : 'radio.html' ,
263
282
styleUrls : [ 'radio.css' ] ,
264
- encapsulation : ViewEncapsulation . None
283
+ encapsulation : ViewEncapsulation . None ,
284
+ changeDetection : ChangeDetectionStrategy . OnPush ,
265
285
} )
266
286
export class MdRadioButton implements OnInit {
267
287
@@ -281,10 +301,26 @@ export class MdRadioButton implements OnInit {
281
301
name : string ;
282
302
283
303
/** Used to set the 'aria-label' attribute on the underlying input element. */
284
- @Input ( 'aria-label' ) ariaLabel : string ;
304
+ _ariaLabel : string ;
305
+ @Input ( 'aria-label' )
306
+ get ariaLabel ( ) : string {
307
+ return this . _ariaLabel ;
308
+ }
309
+ set ariaLabel ( value : string ) {
310
+ this . _ariaLabel = value ;
311
+ this . _change . markForCheck ( ) ;
312
+ }
285
313
286
314
/** The 'aria-labelledby' attribute takes precedence as the element's text alternative. */
287
- @Input ( 'aria-labelledby' ) ariaLabelledby : string ;
315
+ _ariaLabelledby : string ;
316
+ @Input ( 'aria-labelledby' )
317
+ get ariaLabelledby ( ) : string {
318
+ return this . _ariaLabelledby ;
319
+ }
320
+ set ariaLabelledby ( value : string ) {
321
+ this . _ariaLabelledby = value ;
322
+ this . _change . markForCheck ( ) ;
323
+ }
288
324
289
325
/** Whether this radio is disabled. */
290
326
private _disabled : boolean ;
@@ -301,7 +337,10 @@ export class MdRadioButton implements OnInit {
301
337
/** Whether the ripple effect for this radio button is disabled. */
302
338
@Input ( )
303
339
get disableRipple ( ) : boolean { return this . _disableRipple ; }
304
- set disableRipple ( value ) { this . _disableRipple = coerceBooleanProperty ( value ) ; }
340
+ set disableRipple ( value ) {
341
+ this . _disableRipple = coerceBooleanProperty ( value ) ;
342
+ this . _change . markForCheck ( ) ;
343
+ }
305
344
306
345
/**
307
346
* Event emitted when the checked state of this radio button changes.
@@ -317,6 +356,7 @@ export class MdRadioButton implements OnInit {
317
356
constructor ( @Optional ( ) radioGroup : MdRadioGroup ,
318
357
private _elementRef : ElementRef ,
319
358
private _renderer : Renderer ,
359
+ private _change : ChangeDetectorRef ,
320
360
public radioDispatcher : UniqueSelectionDispatcher ) {
321
361
// Assertions. Ideally these should be stripped out by the compiler.
322
362
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -358,6 +398,7 @@ export class MdRadioButton implements OnInit {
358
398
// Notify all radio buttons with the same name to un-check.
359
399
this . radioDispatcher . notify ( this . id , this . name ) ;
360
400
}
401
+ this . _change . markForCheck ( ) ;
361
402
}
362
403
}
363
404
@@ -379,7 +420,7 @@ export class MdRadioButton implements OnInit {
379
420
this . radioGroup . selected = this ;
380
421
}
381
422
}
382
-
423
+ this . _change . markForCheck ( ) ;
383
424
}
384
425
}
385
426
@@ -396,6 +437,7 @@ export class MdRadioButton implements OnInit {
396
437
397
438
set align ( v ) {
398
439
this . labelPosition = ( v == 'start' ) ? 'after' : 'before' ;
440
+ this . _change . markForCheck ( ) ;
399
441
}
400
442
401
443
private _labelPosition : 'before' | 'after' ;
@@ -408,6 +450,7 @@ export class MdRadioButton implements OnInit {
408
450
409
451
set labelPosition ( value ) {
410
452
this . _labelPosition = value ;
453
+ this . _change . markForCheck ( ) ;
411
454
}
412
455
413
456
/** Whether the radio button is disabled. */
@@ -420,6 +463,7 @@ export class MdRadioButton implements OnInit {
420
463
set disabled ( value : boolean ) {
421
464
// The presence of *any* disabled value makes the component disabled, *except* for false.
422
465
this . _disabled = ( value != null && value !== false ) ? true : null ;
466
+ this . _change . markForCheck ( ) ;
423
467
}
424
468
425
469
ngOnInit ( ) {
0 commit comments