@@ -59,33 +59,12 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
59
59
60
60
/** Singleton check box adapter. */
61
61
class CheckBoxAdapter implements MDCCheckboxAdapter {
62
+ constructor ( private readonly _delegate : MatCheckbox ) { }
62
63
63
- private static _adapter : CheckBoxAdapter ;
64
-
65
- private _delegate : MatCheckbox ;
66
-
67
- private constructor ( delegate : MatCheckbox ) {
68
- this . _delegate = delegate ;
69
- }
70
-
71
- useDelegate ( delegate : MatCheckbox ) {
72
- if ( ! this . _delegate ) {
73
- CheckBoxAdapter . _adapter = new CheckBoxAdapter ( delegate ) ;
74
- } else {
75
- this . _delegate = delegate ;
76
- }
77
-
78
- return CheckBoxAdapter . getAdapter ( ) ;
79
- }
80
-
81
- static getAdapter ( ) {
82
- return CheckBoxAdapter . _adapter ;
83
- }
84
-
85
- addClass ( className ) {
64
+ addClass ( className : string ) {
86
65
return this . _delegate . setClass ( className , true ) ;
87
66
}
88
- removeClass ( className ) {
67
+ removeClass ( className : string ) {
89
68
return this . _delegate . setClass ( className , false ) ;
90
69
}
91
70
forceLayout ( ) {
@@ -103,24 +82,21 @@ class CheckBoxAdapter implements MDCCheckboxAdapter {
103
82
isIndeterminate ( ) {
104
83
return this . _delegate . indeterminate ;
105
84
}
106
- removeNativeControlAttr ( attr ) {
85
+ removeNativeControlAttr ( attr : string ) {
107
86
if ( ! this . _delegate . getAttrBlacklist ( ) . has ( attr ) ) {
108
87
this . _delegate . _nativeCheckbox . nativeElement . removeAttribute ( attr ) ;
109
88
}
110
89
}
111
- setNativeControlAttr ( attr , value ) {
90
+ setNativeControlAttr ( attr : string , value : string ) {
112
91
if ( ! this . _delegate . getAttrBlacklist ( ) . has ( attr ) ) {
113
92
this . _delegate . _nativeCheckbox . nativeElement . setAttribute ( attr , value ) ;
114
93
}
115
94
}
116
- setNativeControlDisabled ( disabled ) {
95
+ setNativeControlDisabled ( disabled : boolean ) {
117
96
this . _delegate . disabled = disabled ;
118
97
}
119
98
}
120
99
121
- const _singletonCheckboxAdapter = CheckBoxAdapter . getAdapter ( ) ;
122
-
123
-
124
100
@Component ( {
125
101
selector : 'mat-checkbox' ,
126
102
templateUrl : 'checkbox.html' ,
@@ -273,6 +249,9 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
273
249
*/
274
250
private _attrBlacklist = new Set ( [ 'aria-checked' ] ) ;
275
251
252
+ /** The `MDCCheckboxAdapter` instance for this checkbox. */
253
+ private _adapter : CheckBoxAdapter ;
254
+
276
255
constructor (
277
256
private _changeDetectorRef : ChangeDetectorRef ,
278
257
@Attribute ( 'tabindex' ) tabIndex : string ,
@@ -288,8 +267,8 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
288
267
// Note: We don't need to set up the MDCFormFieldFoundation. Its only purpose is to manage the
289
268
// ripple, which we do ourselves instead.
290
269
this . tabIndex = parseInt ( tabIndex ) || 0 ;
291
- this . _checkboxFoundation = new MDCCheckboxFoundation (
292
- _singletonCheckboxAdapter . useDelegate ( this ) ) ;
270
+ this . _adapter = new CheckBoxAdapter ( this ) ;
271
+ this . _checkboxFoundation = new MDCCheckboxFoundation ( this . _adapter ) ;
293
272
294
273
this . _options = this . _options || { } ;
295
274
0 commit comments