@@ -43,7 +43,9 @@ var _uniqueIdCounter = 0;
43
43
44
44
/** Change event object emitted by MdRadio and MdRadioGroup. */
45
45
export class MdRadioChange {
46
+ /** The MdRadioButton that emits the change event. */
46
47
source : MdRadioButton ;
48
+ /** The value of the MdRadioButton. */
47
49
value : any ;
48
50
}
49
51
@@ -270,9 +272,6 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
270
272
} )
271
273
export class MdRadioButton implements OnInit , AfterViewInit , OnDestroy {
272
274
273
- /** Whether this radio is checked. */
274
- private _checked : boolean = false ;
275
-
276
275
/** The unique ID for the radio button. */
277
276
@Input ( ) id : string = `md-radio-${ _uniqueIdCounter ++ } ` ;
278
277
@@ -285,65 +284,11 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
285
284
/** The 'aria-labelledby' attribute takes precedence as the element's text alternative. */
286
285
@Input ( 'aria-labelledby' ) ariaLabelledby : string ;
287
286
288
- /** Whether this radio is disabled. */
289
- private _disabled : boolean ;
290
-
291
- /** Value assigned to this radio.*/
292
- private _value : any = null ;
293
-
294
- /** Whether the ripple effect on click should be disabled. */
295
- private _disableRipple : boolean ;
296
-
297
- /** The child ripple instance. */
298
- @ViewChild ( MdRipple ) _ripple : MdRipple ;
299
-
300
- /** Stream of focus event from the focus origin monitor. */
301
- private _focusOriginMonitorSubscription : Subscription ;
302
-
303
- /** Reference to the current focus ripple. */
304
- private _focusedRippleRef : RippleRef ;
305
-
306
- /** The parent radio group. May or may not be present. */
307
- radioGroup : MdRadioGroup ;
308
-
309
287
/** Whether the ripple effect for this radio button is disabled. */
310
288
@Input ( )
311
289
get disableRipple ( ) : boolean { return this . _disableRipple ; }
312
290
set disableRipple ( value ) { this . _disableRipple = coerceBooleanProperty ( value ) ; }
313
291
314
- /**
315
- * Event emitted when the checked state of this radio button changes.
316
- * Change events are only emitted when the value changes due to user interaction with
317
- * the radio button (the same behavior as `<input type-"radio">`).
318
- */
319
- @Output ( )
320
- change : EventEmitter < MdRadioChange > = new EventEmitter < MdRadioChange > ( ) ;
321
-
322
- /** The native `<input type=radio>` element */
323
- @ViewChild ( 'input' ) _inputElement : ElementRef ;
324
-
325
- constructor ( @Optional ( ) radioGroup : MdRadioGroup ,
326
- private _elementRef : ElementRef ,
327
- private _renderer : Renderer ,
328
- private _focusOriginMonitor : FocusOriginMonitor ,
329
- public radioDispatcher : UniqueSelectionDispatcher ) {
330
- // Assertions. Ideally these should be stripped out by the compiler.
331
- // TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
332
-
333
- this . radioGroup = radioGroup ;
334
-
335
- radioDispatcher . listen ( ( id : string , name : string ) => {
336
- if ( id != this . id && name == this . name ) {
337
- this . checked = false ;
338
- }
339
- } ) ;
340
- }
341
-
342
- /** ID of the native input element inside `<md-radio-button>` */
343
- get inputId ( ) : string {
344
- return `${ this . id } -input` ;
345
- }
346
-
347
292
/** Whether this radio button is checked. */
348
293
@Input ( )
349
294
get checked ( ) : boolean {
@@ -364,7 +309,7 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
364
309
365
310
if ( newCheckedState ) {
366
311
// Notify all radio buttons with the same name to un-check.
367
- this . radioDispatcher . notify ( this . id , this . name ) ;
312
+ this . _radioDispatcher . notify ( this . id , this . name ) ;
368
313
}
369
314
}
370
315
}
@@ -429,6 +374,68 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
429
374
this . _disabled = ( value != null && value !== false ) ? true : null ;
430
375
}
431
376
377
+ /**
378
+ * Event emitted when the checked state of this radio button changes.
379
+ * Change events are only emitted when the value changes due to user interaction with
380
+ * the radio button (the same behavior as `<input type-"radio">`).
381
+ */
382
+ @Output ( )
383
+ change : EventEmitter < MdRadioChange > = new EventEmitter < MdRadioChange > ( ) ;
384
+
385
+ /** The parent radio group. May or may not be present. */
386
+ radioGroup : MdRadioGroup ;
387
+
388
+ /** ID of the native input element inside `<md-radio-button>` */
389
+ get inputId ( ) : string {
390
+ return `${ this . id } -input` ;
391
+ }
392
+
393
+ /** Whether this radio is checked. */
394
+ private _checked : boolean = false ;
395
+
396
+ /** Whether this radio is disabled. */
397
+ private _disabled : boolean ;
398
+
399
+ /** Value assigned to this radio.*/
400
+ private _value : any = null ;
401
+
402
+ /** Whether the ripple effect on click should be disabled. */
403
+ private _disableRipple : boolean ;
404
+
405
+ /** The child ripple instance. */
406
+ @ViewChild ( MdRipple ) _ripple : MdRipple ;
407
+
408
+ /** Stream of focus event from the focus origin monitor. */
409
+ private _focusOriginMonitorSubscription : Subscription ;
410
+
411
+ /** Reference to the current focus ripple. */
412
+ private _focusedRippleRef : RippleRef ;
413
+
414
+ /** The native `<input type=radio>` element */
415
+ @ViewChild ( 'input' ) _inputElement : ElementRef ;
416
+
417
+ constructor ( @Optional ( ) radioGroup : MdRadioGroup ,
418
+ private _elementRef : ElementRef ,
419
+ private _renderer : Renderer ,
420
+ private _focusOriginMonitor : FocusOriginMonitor ,
421
+ private _radioDispatcher : UniqueSelectionDispatcher ) {
422
+ // Assertions. Ideally these should be stripped out by the compiler.
423
+ // TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
424
+
425
+ this . radioGroup = radioGroup ;
426
+
427
+ _radioDispatcher . listen ( ( id : string , name : string ) => {
428
+ if ( id != this . id && name == this . name ) {
429
+ this . checked = false ;
430
+ }
431
+ } ) ;
432
+ }
433
+
434
+ /** Focuses the radio button. */
435
+ focus ( ) : void {
436
+ this . _focusOriginMonitor . focusVia ( this . _inputElement . nativeElement , this . _renderer , 'keyboard' ) ;
437
+ }
438
+
432
439
ngOnInit ( ) {
433
440
if ( this . radioGroup ) {
434
441
// If the radio is inside a radio group, determine if it should be checked
@@ -469,11 +476,6 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
469
476
return this . disableRipple || this . disabled ;
470
477
}
471
478
472
- /** Focuses the radio button. */
473
- focus ( ) : void {
474
- this . _focusOriginMonitor . focusVia ( this . _inputElement . nativeElement , this . _renderer , 'keyboard' ) ;
475
- }
476
-
477
479
_onInputBlur ( ) {
478
480
if ( this . _focusedRippleRef ) {
479
481
this . _focusedRippleRef . fadeOut ( ) ;
0 commit comments