@@ -32,15 +32,13 @@ import {
32
32
} from '@angular/core' ;
33
33
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
34
34
import {
35
- CanColor ,
36
- CanColorCtor ,
37
35
CanDisableRipple ,
38
36
CanDisableRippleCtor ,
39
37
HasTabIndex ,
40
38
HasTabIndexCtor ,
41
- mixinColor ,
42
39
mixinDisableRipple ,
43
40
mixinTabIndex ,
41
+ ThemePalette ,
44
42
} from '@angular/material/core' ;
45
43
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
46
44
@@ -122,6 +120,9 @@ export class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
122
120
@ContentChildren ( forwardRef ( ( ) => MatRadioButton ) , { descendants : true } )
123
121
_radios : QueryList < MatRadioButton > ;
124
122
123
+ /** Theme color for all of the radio buttons in the group. */
124
+ @Input ( ) color : ThemePalette ;
125
+
125
126
/** Name of the radio button group. All radio buttons inside this group will use this name. */
126
127
@Input ( )
127
128
get name ( ) : string { return this . _name ; }
@@ -303,8 +304,8 @@ export class MatRadioButtonBase {
303
304
// As per Material design specifications the selection control radio should use the accent color
304
305
// palette by default. https://material.io/guidelines/components/selection-controls.html
305
306
export const _MatRadioButtonMixinBase :
306
- CanColorCtor & CanDisableRippleCtor & HasTabIndexCtor & typeof MatRadioButtonBase =
307
- mixinColor ( mixinDisableRipple ( mixinTabIndex ( MatRadioButtonBase ) ) , 'accent' ) ;
307
+ CanDisableRippleCtor & HasTabIndexCtor & typeof MatRadioButtonBase =
308
+ mixinDisableRipple ( mixinTabIndex ( MatRadioButtonBase ) ) ;
308
309
309
310
/**
310
311
* A Material design radio-button. Typically placed inside of `<mat-radio-group>` elements.
@@ -314,14 +315,17 @@ export const _MatRadioButtonMixinBase:
314
315
selector : 'mat-radio-button' ,
315
316
templateUrl : 'radio.html' ,
316
317
styleUrls : [ 'radio.css' ] ,
317
- inputs : [ 'color' , ' disableRipple', 'tabIndex' ] ,
318
+ inputs : [ 'disableRipple' , 'tabIndex' ] ,
318
319
encapsulation : ViewEncapsulation . None ,
319
320
exportAs : 'matRadioButton' ,
320
321
host : {
321
322
'class' : 'mat-radio-button' ,
322
323
'[class.mat-radio-checked]' : 'checked' ,
323
324
'[class.mat-radio-disabled]' : 'disabled' ,
324
325
'[class._mat-animation-noopable]' : '_animationMode === "NoopAnimations"' ,
326
+ '[class.mat-primary]' : 'color === "primary"' ,
327
+ '[class.mat-accent]' : 'color === "accent"' ,
328
+ '[class.mat-warn]' : 'color === "warn"' ,
325
329
// Needs to be -1 so the `focus` event still fires.
326
330
'[attr.tabindex]' : '-1' ,
327
331
'[attr.id]' : 'id' ,
@@ -333,7 +337,7 @@ export const _MatRadioButtonMixinBase:
333
337
changeDetection : ChangeDetectionStrategy . OnPush ,
334
338
} )
335
339
export class MatRadioButton extends _MatRadioButtonMixinBase
336
- implements OnInit , AfterViewInit , OnDestroy , CanColor , CanDisableRipple , HasTabIndex {
340
+ implements OnInit , AfterViewInit , OnDestroy , CanDisableRipple , HasTabIndex {
337
341
338
342
private _uniqueId : string = `mat-radio-${ ++ nextUniqueId } ` ;
339
343
@@ -426,6 +430,14 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
426
430
this . _required = coerceBooleanProperty ( value ) ;
427
431
}
428
432
433
+ /** Theme color of the radio button. */
434
+ @Input ( )
435
+ get color ( ) : ThemePalette {
436
+ return this . _color || ( this . radioGroup && this . radioGroup . color ) || 'accent' ;
437
+ }
438
+ set color ( newValue : ThemePalette ) { this . _color = newValue ; }
439
+ private _color : ThemePalette ;
440
+
429
441
/**
430
442
* Event emitted when the checked state of this radio button changes.
431
443
* Change events are only emitted when the value changes due to user interaction with
0 commit comments