@@ -38,6 +38,7 @@ import {
3838import { coerceBooleanProperty } from '@angular/cdk' ;
3939import { mixinDisabled , CanDisable } from '../core/common-behaviors/disabled' ;
4040import { CanColor , mixinColor } from '../core/common-behaviors/color' ;
41+ import { CanId , mixinId } from '../core/common-behaviors/id' ;
4142
4243
4344/**
@@ -51,8 +52,6 @@ export const MD_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any = {
5152 multi : true
5253} ;
5354
54- let _uniqueIdCounter = 0 ;
55-
5655/** Change event object emitted by MdRadio and MdRadioGroup. */
5756export class MdRadioChange {
5857 /** The MdRadioButton that emits the change event. */
@@ -65,7 +64,7 @@ export class MdRadioChange {
6564// Boilerplate for applying mixins to MdRadioGroup.
6665/** @docs -private */
6766export class MdRadioGroupBase { }
68- export const _MdRadioGroupMixinBase = mixinDisabled ( MdRadioGroupBase ) ;
67+ export const _MdRadioGroupMixinBase = mixinId ( mixinDisabled ( MdRadioGroupBase ) , 'md-radio-group' ) ;
6968
7069/**
7170 * A group of radio buttons. May contain one or more `<md-radio-button>` elements.
@@ -76,11 +75,12 @@ export const _MdRadioGroupMixinBase = mixinDisabled(MdRadioGroupBase);
7675 host : {
7776 'role' : 'radiogroup' ,
7877 'class' : 'mat-radio-group' ,
78+ '[id]' : 'id' ,
7979 } ,
8080 inputs : [ 'disabled' ] ,
8181} )
8282export class MdRadioGroup extends _MdRadioGroupMixinBase
83- implements AfterContentInit , ControlValueAccessor , CanDisable {
83+ implements AfterContentInit , ControlValueAccessor , CanDisable , CanId {
8484 /**
8585 * Selected value for group. Should equal the value of the selected radio button if there *is*
8686 * a corresponding radio button with a matching value. If there is *not* such a corresponding
@@ -90,7 +90,7 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase
9090 private _value : any = null ;
9191
9292 /** The HTML name attribute applied to radio buttons in this group. */
93- private _name : string = `md-radio-group- ${ _uniqueIdCounter ++ } ` ;
93+ private _name : string = this . id ;
9494
9595 /** The currently selected radio button. Should match value. */
9696 private _selected : MdRadioButton | null = null ;
@@ -303,7 +303,8 @@ export class MdRadioButtonBase {
303303}
304304// As per Material design specifications the selection control radio should use the accent color
305305// palette by default. https://material.io/guidelines/components/selection-controls.html
306- export const _MdRadioButtonMixinBase = mixinColor ( MdRadioButtonBase , 'accent' ) ;
306+ export const _MdRadioButtonMixinBase =
307+ mixinId ( mixinColor ( MdRadioButtonBase , 'accent' ) , 'md-radio-button' ) ;
307308
308309/**
309310 * A radio-button. May be inside of
@@ -313,7 +314,7 @@ export const _MdRadioButtonMixinBase = mixinColor(MdRadioButtonBase, 'accent');
313314 selector : 'md-radio-button, mat-radio-button' ,
314315 templateUrl : 'radio.html' ,
315316 styleUrls : [ 'radio.css' ] ,
316- inputs : [ 'color' ] ,
317+ inputs : [ 'color' , 'id' ] ,
317318 encapsulation : ViewEncapsulation . None ,
318319 host : {
319320 'class' : 'mat-radio-button' ,
@@ -324,13 +325,10 @@ export const _MdRadioButtonMixinBase = mixinColor(MdRadioButtonBase, 'accent');
324325 changeDetection : ChangeDetectionStrategy . OnPush ,
325326} )
326327export class MdRadioButton extends _MdRadioButtonMixinBase
327- implements OnInit , AfterViewInit , OnDestroy , CanColor {
328-
329- /** The unique ID for the radio button. */
330- @Input ( ) id : string = `md-radio-${ _uniqueIdCounter ++ } ` ;
328+ implements OnInit , AfterViewInit , OnDestroy , CanColor , CanId {
331329
332330 /** Analog to HTML 'name' attribute used to group radios for unique selection. */
333- @Input ( ) name : string ;
331+ @Input ( ) name : string = this . id ;
334332
335333 /** Used to set the 'aria-label' attribute on the underlying input element. */
336334 @Input ( 'aria-label' ) ariaLabel : string ;
@@ -437,9 +435,7 @@ export class MdRadioButton extends _MdRadioButtonMixinBase
437435 radioGroup : MdRadioGroup ;
438436
439437 /** ID of the native input element inside `<md-radio-button>` */
440- get inputId ( ) : string {
441- return `${ this . id } -input` ;
442- }
438+ get inputId ( ) : string { return `${ this . id } -input` ; }
443439
444440 /** Whether this radio is checked. */
445441 private _checked : boolean = false ;
0 commit comments