@@ -78,32 +78,27 @@ export const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any = {
78
78
export class MatRadioChange {
79
79
constructor (
80
80
/** The MatRadioButton that emits the change event. */
81
- public source : MatRadioButton ,
81
+ public source : _MatRadioButtonBase ,
82
82
/** The value of the MatRadioButton. */
83
83
public value : any ) { }
84
84
}
85
85
86
86
/**
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
88
89
*/
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 {
99
94
/** Selected value for the radio group. */
100
95
private _value : any = null ;
101
96
102
97
/** The HTML name attribute applied to radio buttons in this group. */
103
98
private _name : string = `mat-radio-group-${ nextUniqueId ++ } ` ;
104
99
105
100
/** The currently selected radio button. Should match value. */
106
- private _selected : MatRadioButton | null = null ;
101
+ private _selected : T | null = null ;
107
102
108
103
/** Whether the `value` has been set to its initial value. */
109
104
private _isInitialized : boolean = false ;
@@ -134,8 +129,7 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
134
129
@Output ( ) readonly change : EventEmitter < MatRadioChange > = new EventEmitter < MatRadioChange > ( ) ;
135
130
136
131
/** Child radio buttons. */
137
- @ContentChildren ( forwardRef ( ( ) => MatRadioButton ) , { descendants : true } )
138
- _radios : QueryList < MatRadioButton > ;
132
+ abstract _radios : QueryList < T > ;
139
133
140
134
/** Theme color for all of the radio buttons in the group. */
141
135
@Input ( ) color : ThemePalette ;
@@ -188,7 +182,7 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
188
182
*/
189
183
@Input ( )
190
184
get selected ( ) { return this . _selected ; }
191
- set selected ( selected : MatRadioButton | null ) {
185
+ set selected ( selected : T | null ) {
192
186
this . _selected = selected ;
193
187
this . value = selected ? selected . value : null ;
194
188
this . _checkSelectedRadioButton ( ) ;
@@ -311,6 +305,23 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
311
305
static ngAcceptInputType_required : BooleanInput ;
312
306
}
313
307
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
+
314
325
// Boilerplate for applying mixins to MatRadioButton.
315
326
/** @docs -private */
316
327
class MatRadioButtonBase {
@@ -441,7 +452,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
441
452
@Output ( ) readonly change : EventEmitter < MatRadioChange > = new EventEmitter < MatRadioChange > ( ) ;
442
453
443
454
/** The parent radio group. May or may not be present. */
444
- radioGroup : MatRadioGroup ;
455
+ radioGroup : _MatRadioGroupBase < _MatRadioButtonBase > ;
445
456
446
457
/** ID of the native input element inside `<mat-radio-button>` */
447
458
get inputId ( ) : string { return `${ this . id || this . _uniqueId } -input` ; }
@@ -464,7 +475,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
464
475
/** The native `<input type=radio>` element */
465
476
@ViewChild ( 'input' ) _inputElement : ElementRef < HTMLInputElement > ;
466
477
467
- constructor ( @Optional ( ) radioGroup : MatRadioGroup ,
478
+ constructor ( @Optional ( ) radioGroup : _MatRadioGroupBase < _MatRadioButtonBase > ,
468
479
elementRef : ElementRef ,
469
480
protected _changeDetector : ChangeDetectorRef ,
470
481
private _focusMonitor : FocusMonitor ,
@@ -615,4 +626,15 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
615
626
changeDetection : ChangeDetectionStrategy . OnPush ,
616
627
} )
617
628
export 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
+ }
618
640
}
0 commit comments