@@ -30,7 +30,16 @@ import {
3030 MAT_CHECKBOX_DEFAULT_OPTIONS ,
3131 MatCheckboxClickAction , MatCheckboxDefaultOptions
3232} from '@angular/material/checkbox' ;
33- import { ThemePalette , RippleAnimationConfig } from '@angular/material/core' ;
33+ import {
34+ ThemePalette ,
35+ RippleAnimationConfig ,
36+ CanColorCtor ,
37+ CanDisableCtor ,
38+ mixinColor ,
39+ mixinDisabled ,
40+ CanColor ,
41+ CanDisable ,
42+ } from '@angular/material/core' ;
3443import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
3544import { MDCCheckboxAdapter , MDCCheckboxFoundation } from '@material/checkbox' ;
3645import { numbers } from '@material/ripple' ;
@@ -51,6 +60,18 @@ export class MatCheckboxChange {
5160 checked : boolean ;
5261}
5362
63+ // Boilerplate for applying mixins to MatCheckbox.
64+ /** @docs -private */
65+ class MatCheckboxBase {
66+ constructor ( public _elementRef : ElementRef ) { }
67+ }
68+ const _MatCheckboxMixinBase :
69+ CanColorCtor &
70+ CanDisableCtor &
71+ typeof MatCheckboxBase =
72+ mixinColor ( mixinDisabled ( MatCheckboxBase ) ) ;
73+
74+
5475/** Configuration for the ripple animation. */
5576const RIPPLE_ANIMATION_CONFIG : RippleAnimationConfig = {
5677 enterDuration : numbers . DEACTIVATION_TIMEOUT_MS ,
@@ -61,12 +82,10 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
6182 selector : 'mat-checkbox' ,
6283 templateUrl : 'checkbox.html' ,
6384 styleUrls : [ 'checkbox.css' ] ,
85+ inputs : [ 'color' , 'disabled' ] ,
6486 host : {
6587 'class' : 'mat-mdc-checkbox' ,
6688 '[attr.tabindex]' : 'null' ,
67- '[class.mat-primary]' : 'color == "primary"' ,
68- '[class.mat-accent]' : 'color == "accent"' ,
69- '[class.mat-warn]' : 'color == "warn"' ,
7089 '[class._mat-animation-noopable]' : `_animationMode === 'NoopAnimations'` ,
7190 '[class.mdc-checkbox--disabled]' : 'disabled' ,
7291 '[id]' : 'id' ,
@@ -76,7 +95,8 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
7695 encapsulation : ViewEncapsulation . None ,
7796 changeDetection : ChangeDetectionStrategy . OnPush ,
7897} )
79- export class MatCheckbox implements AfterViewInit , OnDestroy , ControlValueAccessor {
98+ export class MatCheckbox extends _MatCheckboxMixinBase implements AfterViewInit , OnDestroy ,
99+ ControlValueAccessor , CanColor , CanDisable {
80100 /**
81101 * The `aria-label` attribute to use for the input element. In most cases, `aria-labelledby` will
82102 * take precedence so this may be omitted.
@@ -135,16 +155,6 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
135155 }
136156 private _indeterminate = false ;
137157
138- /** Whether the checkbox is disabled. */
139- @Input ( )
140- get disabled ( ) : boolean {
141- return this . _disabled ;
142- }
143- set disabled ( disabled ) {
144- this . _disabled = coerceBooleanProperty ( disabled ) ;
145- }
146- private _disabled = false ;
147-
148158 /** Whether the checkbox is required. */
149159 @Input ( )
150160 get required ( ) : boolean {
@@ -235,6 +245,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
235245
236246 constructor (
237247 private _changeDetectorRef : ChangeDetectorRef ,
248+ elementRef : ElementRef < HTMLElement > ,
238249 @Attribute ( 'tabindex' ) tabIndex : string ,
239250 /**
240251 * @deprecated `_clickAction` parameter to be removed, use
@@ -245,6 +256,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
245256 @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ,
246257 @Optional ( ) @Inject ( MAT_CHECKBOX_DEFAULT_OPTIONS )
247258 private _options ?: MatCheckboxDefaultOptions ) {
259+ super ( elementRef ) ;
248260 // Note: We don't need to set up the MDCFormFieldFoundation. Its only purpose is to manage the
249261 // ripple, which we do ourselves instead.
250262 this . tabIndex = parseInt ( tabIndex ) || 0 ;
@@ -253,7 +265,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
253265 this . _options = this . _options || { } ;
254266
255267 if ( this . _options . color ) {
256- this . color = this . _options . color ;
268+ this . color = this . defaultColor = this . _options . color ;
257269 }
258270
259271 // @breaking -change 10.0.0: Remove this after the `_clickAction` parameter is removed as an
0 commit comments