1
1
import {
2
2
AfterContentInit ,
3
+ ChangeDetectionStrategy ,
4
+ ChangeDetectorRef ,
3
5
Component ,
4
6
ContentChildren ,
5
7
Directive ,
@@ -126,14 +128,31 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
126
128
}
127
129
128
130
/** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
129
- @Input ( ) labelPosition : 'before' | 'after' = 'after' ;
131
+ _labelPosition : 'before' | 'after' = 'after' ;
132
+ @Input ( )
133
+ get labelPosition ( ) : 'before' | 'after' {
134
+ return this . _labelPosition ;
135
+ }
136
+ set labelPosition ( v : 'before' | 'after' ) {
137
+ this . _labelPosition = v
138
+ if ( this . _radios ) {
139
+ this . _radios . forEach ( ( radio ) => {
140
+ radio . labelPosition = this . _labelPosition ;
141
+ } ) ;
142
+ }
143
+ }
130
144
131
145
/** Whether the radio button is disabled. */
132
146
@Input ( )
133
147
get disabled ( ) : boolean { return this . _disabled ; }
134
148
set disabled ( value ) {
135
149
// The presence of *any* disabled value makes the component disabled, *except* for false.
136
150
this . _disabled = ( value != null && value !== false ) ? true : null ;
151
+ if ( this . _radios ) {
152
+ this . _radios . forEach ( ( radio ) => {
153
+ radio . disabled = this . _disabled ;
154
+ } )
155
+ }
137
156
}
138
157
139
158
/** Value of the radio button. */
@@ -266,6 +285,7 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
266
285
host : {
267
286
'[class.mat-radio-button]' : 'true' ,
268
287
}
288
+ changeDetection : ChangeDetectionStrategy . OnPush ,
269
289
} )
270
290
export class MdRadioButton implements OnInit {
271
291
@@ -285,10 +305,26 @@ export class MdRadioButton implements OnInit {
285
305
name : string ;
286
306
287
307
/** Used to set the 'aria-label' attribute on the underlying input element. */
288
- @Input ( 'aria-label' ) ariaLabel : string ;
308
+ _ariaLabel : string ;
309
+ @Input ( 'aria-label' )
310
+ get ariaLabel ( ) : string {
311
+ return this . _ariaLabel ;
312
+ }
313
+ set ariaLabel ( value : string ) {
314
+ this . _ariaLabel = value ;
315
+ this . _change . markForCheck ( ) ;
316
+ }
289
317
290
318
/** The 'aria-labelledby' attribute takes precedence as the element's text alternative. */
291
- @Input ( 'aria-labelledby' ) ariaLabelledby : string ;
319
+ _ariaLabelledby : string ;
320
+ @Input ( 'aria-labelledby' )
321
+ get ariaLabelledby ( ) : string {
322
+ return this . _ariaLabelledby ;
323
+ }
324
+ set ariaLabelledby ( value : string ) {
325
+ this . _ariaLabelledby = value ;
326
+ this . _change . markForCheck ( ) ;
327
+ }
292
328
293
329
/** Whether this radio is disabled. */
294
330
private _disabled : boolean ;
@@ -305,7 +341,10 @@ export class MdRadioButton implements OnInit {
305
341
/** Whether the ripple effect for this radio button is disabled. */
306
342
@Input ( )
307
343
get disableRipple ( ) : boolean { return this . _disableRipple ; }
308
- set disableRipple ( value ) { this . _disableRipple = coerceBooleanProperty ( value ) ; }
344
+ set disableRipple ( value ) {
345
+ this . _disableRipple = coerceBooleanProperty ( value ) ;
346
+ this . _change . markForCheck ( ) ;
347
+ }
309
348
310
349
/**
311
350
* Event emitted when the checked state of this radio button changes.
@@ -321,6 +360,7 @@ export class MdRadioButton implements OnInit {
321
360
constructor ( @Optional ( ) radioGroup : MdRadioGroup ,
322
361
private _elementRef : ElementRef ,
323
362
private _renderer : Renderer ,
363
+ private _change : ChangeDetectorRef ,
324
364
public radioDispatcher : UniqueSelectionDispatcher ) {
325
365
// Assertions. Ideally these should be stripped out by the compiler.
326
366
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
@@ -362,6 +402,7 @@ export class MdRadioButton implements OnInit {
362
402
// Notify all radio buttons with the same name to un-check.
363
403
this . radioDispatcher . notify ( this . id , this . name ) ;
364
404
}
405
+ this . _change . markForCheck ( ) ;
365
406
}
366
407
}
367
408
@@ -383,7 +424,7 @@ export class MdRadioButton implements OnInit {
383
424
this . radioGroup . selected = this ;
384
425
}
385
426
}
386
-
427
+ this . _change . markForCheck ( ) ;
387
428
}
388
429
}
389
430
@@ -400,6 +441,7 @@ export class MdRadioButton implements OnInit {
400
441
401
442
set align ( v ) {
402
443
this . labelPosition = ( v == 'start' ) ? 'after' : 'before' ;
444
+ this . _change . markForCheck ( ) ;
403
445
}
404
446
405
447
private _labelPosition : 'before' | 'after' ;
@@ -412,6 +454,7 @@ export class MdRadioButton implements OnInit {
412
454
413
455
set labelPosition ( value ) {
414
456
this . _labelPosition = value ;
457
+ this . _change . markForCheck ( ) ;
415
458
}
416
459
417
460
/** Whether the radio button is disabled. */
@@ -424,6 +467,7 @@ export class MdRadioButton implements OnInit {
424
467
set disabled ( value : boolean ) {
425
468
// The presence of *any* disabled value makes the component disabled, *except* for false.
426
469
this . _disabled = ( value != null && value !== false ) ? true : null ;
470
+ this . _change . markForCheck ( ) ;
427
471
}
428
472
429
473
ngOnInit ( ) {
0 commit comments