@@ -78,32 +78,27 @@ export const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any = {
7878export class MatRadioChange {
7979 constructor (
8080 /** The MatRadioButton that emits the change event. */
81- public source : MatRadioButton ,
81+ public source : _MatRadioButtonBase ,
8282 /** The value of the MatRadioButton. */
8383 public value : any ) { }
8484}
8585
8686/**
87- * A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
87+ * Base class with all of the `MatRadioGroup` functionality.
88+ * @docs -private
8889 */
89- @Directive ( {
90- selector : 'mat-radio-group' ,
91- exportAs : 'matRadioGroup' ,
92- providers : [ MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR ] ,
93- host : {
94- 'role' : 'radiogroup' ,
95- 'class' : 'mat-radio-group' ,
96- } ,
97- } )
98- export class MatRadioGroup implements AfterContentInit , ControlValueAccessor {
90+ @Directive ( )
91+ // tslint:disable-next-line:class-name
92+ export abstract class _MatRadioGroupBase < T extends _MatRadioButtonBase > implements AfterContentInit ,
93+ ControlValueAccessor {
9994 /** Selected value for the radio group. */
10095 private _value : any = null ;
10196
10297 /** The HTML name attribute applied to radio buttons in this group. */
10398 private _name : string = `mat-radio-group-${ nextUniqueId ++ } ` ;
10499
105100 /** The currently selected radio button. Should match value. */
106- private _selected : MatRadioButton | null = null ;
101+ private _selected : T | null = null ;
107102
108103 /** Whether the `value` has been set to its initial value. */
109104 private _isInitialized : boolean = false ;
@@ -134,8 +129,7 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
134129 @Output ( ) readonly change : EventEmitter < MatRadioChange > = new EventEmitter < MatRadioChange > ( ) ;
135130
136131 /** Child radio buttons. */
137- @ContentChildren ( forwardRef ( ( ) => MatRadioButton ) , { descendants : true } )
138- _radios : QueryList < MatRadioButton > ;
132+ abstract _radios : QueryList < T > ;
139133
140134 /** Theme color for all of the radio buttons in the group. */
141135 @Input ( ) color : ThemePalette ;
@@ -188,7 +182,7 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
188182 */
189183 @Input ( )
190184 get selected ( ) { return this . _selected ; }
191- set selected ( selected : MatRadioButton | null ) {
185+ set selected ( selected : T | null ) {
192186 this . _selected = selected ;
193187 this . value = selected ? selected . value : null ;
194188 this . _checkSelectedRadioButton ( ) ;
@@ -311,6 +305,23 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
311305 static ngAcceptInputType_required : BooleanInput ;
312306}
313307
308+ /**
309+ * A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
310+ */
311+ @Directive ( {
312+ selector : 'mat-radio-group' ,
313+ exportAs : 'matRadioGroup' ,
314+ providers : [ MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR ] ,
315+ host : {
316+ 'role' : 'radiogroup' ,
317+ 'class' : 'mat-radio-group' ,
318+ } ,
319+ } )
320+ export class MatRadioGroup extends _MatRadioGroupBase < MatRadioButton > {
321+ @ContentChildren ( forwardRef ( ( ) => MatRadioButton ) , { descendants : true } )
322+ _radios : QueryList < MatRadioButton > ;
323+ }
324+
314325// Boilerplate for applying mixins to MatRadioButton.
315326/** @docs -private */
316327class MatRadioButtonBase {
@@ -441,7 +452,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
441452 @Output ( ) readonly change : EventEmitter < MatRadioChange > = new EventEmitter < MatRadioChange > ( ) ;
442453
443454 /** The parent radio group. May or may not be present. */
444- radioGroup : MatRadioGroup ;
455+ radioGroup : _MatRadioGroupBase < _MatRadioButtonBase > ;
445456
446457 /** ID of the native input element inside `<mat-radio-button>` */
447458 get inputId ( ) : string { return `${ this . id || this . _uniqueId } -input` ; }
@@ -464,7 +475,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
464475 /** The native `<input type=radio>` element */
465476 @ViewChild ( 'input' ) _inputElement : ElementRef < HTMLInputElement > ;
466477
467- constructor ( @Optional ( ) radioGroup : MatRadioGroup ,
478+ constructor ( @Optional ( ) radioGroup : _MatRadioGroupBase < _MatRadioButtonBase > ,
468479 elementRef : ElementRef ,
469480 protected _changeDetector : ChangeDetectorRef ,
470481 private _focusMonitor : FocusMonitor ,
@@ -615,4 +626,15 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
615626 changeDetection : ChangeDetectionStrategy . OnPush ,
616627} )
617628export class MatRadioButton extends _MatRadioButtonBase {
629+ constructor ( @Optional ( ) radioGroup : MatRadioGroup ,
630+ elementRef : ElementRef ,
631+ changeDetector : ChangeDetectorRef ,
632+ focusMonitor : FocusMonitor ,
633+ radioDispatcher : UniqueSelectionDispatcher ,
634+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
635+ @Optional ( ) @Inject ( MAT_RADIO_DEFAULT_OPTIONS )
636+ providerOverride ?: MatRadioDefaultOptions ) {
637+ super ( radioGroup , elementRef , changeDetector , focusMonitor , radioDispatcher ,
638+ animationMode , providerOverride ) ;
639+ }
618640}
0 commit comments