@@ -30,7 +30,16 @@ import {
30
30
MAT_CHECKBOX_DEFAULT_OPTIONS ,
31
31
MatCheckboxClickAction , MatCheckboxDefaultOptions
32
32
} 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' ;
34
43
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
35
44
import { MDCCheckboxAdapter , MDCCheckboxFoundation } from '@material/checkbox' ;
36
45
import { numbers } from '@material/ripple' ;
@@ -51,6 +60,18 @@ export class MatCheckboxChange {
51
60
checked : boolean ;
52
61
}
53
62
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
+
54
75
/** Configuration for the ripple animation. */
55
76
const RIPPLE_ANIMATION_CONFIG : RippleAnimationConfig = {
56
77
enterDuration : numbers . DEACTIVATION_TIMEOUT_MS ,
@@ -61,12 +82,10 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
61
82
selector : 'mat-checkbox' ,
62
83
templateUrl : 'checkbox.html' ,
63
84
styleUrls : [ 'checkbox.css' ] ,
85
+ inputs : [ 'color' , 'disabled' ] ,
64
86
host : {
65
87
'class' : 'mat-mdc-checkbox' ,
66
88
'[attr.tabindex]' : 'null' ,
67
- '[class.mat-primary]' : 'color == "primary"' ,
68
- '[class.mat-accent]' : 'color == "accent"' ,
69
- '[class.mat-warn]' : 'color == "warn"' ,
70
89
'[class._mat-animation-noopable]' : `_animationMode === 'NoopAnimations'` ,
71
90
'[class.mdc-checkbox--disabled]' : 'disabled' ,
72
91
'[id]' : 'id' ,
@@ -76,7 +95,8 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
76
95
encapsulation : ViewEncapsulation . None ,
77
96
changeDetection : ChangeDetectionStrategy . OnPush ,
78
97
} )
79
- export class MatCheckbox implements AfterViewInit , OnDestroy , ControlValueAccessor {
98
+ export class MatCheckbox extends _MatCheckboxMixinBase implements AfterViewInit , OnDestroy ,
99
+ ControlValueAccessor , CanColor , CanDisable {
80
100
/**
81
101
* The `aria-label` attribute to use for the input element. In most cases, `aria-labelledby` will
82
102
* take precedence so this may be omitted.
@@ -135,16 +155,6 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
135
155
}
136
156
private _indeterminate = false ;
137
157
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
-
148
158
/** Whether the checkbox is required. */
149
159
@Input ( )
150
160
get required ( ) : boolean {
@@ -235,6 +245,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
235
245
236
246
constructor (
237
247
private _changeDetectorRef : ChangeDetectorRef ,
248
+ elementRef : ElementRef < HTMLElement > ,
238
249
@Attribute ( 'tabindex' ) tabIndex : string ,
239
250
/**
240
251
* @deprecated `_clickAction` parameter to be removed, use
@@ -245,6 +256,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
245
256
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ,
246
257
@Optional ( ) @Inject ( MAT_CHECKBOX_DEFAULT_OPTIONS )
247
258
private _options ?: MatCheckboxDefaultOptions ) {
259
+ super ( elementRef ) ;
248
260
// Note: We don't need to set up the MDCFormFieldFoundation. Its only purpose is to manage the
249
261
// ripple, which we do ourselves instead.
250
262
this . tabIndex = parseInt ( tabIndex ) || 0 ;
@@ -253,7 +265,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
253
265
this . _options = this . _options || { } ;
254
266
255
267
if ( this . _options . color ) {
256
- this . color = this . _options . color ;
268
+ this . color = this . defaultColor = this . _options . color ;
257
269
}
258
270
259
271
// @breaking -change 10.0.0: Remove this after the `_clickAction` parameter is removed as an
0 commit comments