Skip to content

Commit ef83be6

Browse files
committed
fix(checkbox): add type annotations to CheckboxAdapter methods
Added type annotations to CheckboxAdapter methods to satisfy bazel errors.
1 parent daaf1b6 commit ef83be6

File tree

2 files changed

+16
-57
lines changed

2 files changed

+16
-57
lines changed

src/material-experimental/mdc-checkbox/checkbox.ts

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,12 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
5959

6060
/** Singleton check box adapter. */
6161
class CheckBoxAdapter implements MDCCheckboxAdapter {
62+
constructor(private readonly _delegate: MatCheckbox) {}
6263

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) {
8665
return this._delegate.setClass(className, true);
8766
}
88-
removeClass(className) {
67+
removeClass(className: string) {
8968
return this._delegate.setClass(className, false);
9069
}
9170
forceLayout() {
@@ -103,24 +82,21 @@ class CheckBoxAdapter implements MDCCheckboxAdapter {
10382
isIndeterminate() {
10483
return this._delegate.indeterminate;
10584
}
106-
removeNativeControlAttr(attr) {
85+
removeNativeControlAttr(attr: string) {
10786
if (!this._delegate.getAttrBlacklist().has(attr)) {
10887
this._delegate._nativeCheckbox.nativeElement.removeAttribute(attr);
10988
}
11089
}
111-
setNativeControlAttr(attr, value) {
90+
setNativeControlAttr(attr: string, value: string) {
11291
if (!this._delegate.getAttrBlacklist().has(attr)) {
11392
this._delegate._nativeCheckbox.nativeElement.setAttribute(attr, value);
11493
}
11594
}
116-
setNativeControlDisabled(disabled) {
95+
setNativeControlDisabled(disabled: boolean) {
11796
this._delegate.disabled = disabled;
11897
}
11998
}
12099

121-
const _singletonCheckboxAdapter = CheckBoxAdapter.getAdapter();
122-
123-
124100
@Component({
125101
selector: 'mat-checkbox',
126102
templateUrl: 'checkbox.html',
@@ -273,6 +249,9 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
273249
*/
274250
private _attrBlacklist = new Set(['aria-checked']);
275251

252+
/** The `MDCCheckboxAdapter` instance for this checkbox. */
253+
private _adapter: CheckBoxAdapter;
254+
276255
constructor(
277256
private _changeDetectorRef: ChangeDetectorRef,
278257
@Attribute('tabindex') tabIndex: string,
@@ -288,8 +267,8 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
288267
// Note: We don't need to set up the MDCFormFieldFoundation. Its only purpose is to manage the
289268
// ripple, which we do ourselves instead.
290269
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);
293272

294273
this._options = this._options || {};
295274

src/material-experimental/mdc-radio/radio.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,7 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
6666
};
6767

6868
class RadioAdapter implements MDCRadioAdapter {
69-
70-
private static _adapter: RadioAdapter;
71-
72-
private _delegate: MatRadioButton;
73-
74-
private constructor(delegate: MatRadioButton) {
75-
this._delegate = delegate;
76-
}
77-
78-
useDelegate(delegate: MatRadioButton) {
79-
if (!this._delegate) {
80-
RadioAdapter._adapter = new RadioAdapter(delegate);
81-
} else {
82-
this._delegate = delegate;
83-
}
84-
85-
return RadioAdapter.getAdapter();
86-
}
87-
88-
static getAdapter() {
89-
return RadioAdapter._adapter;
90-
}
91-
69+
constructor(private readonly _delegate: MatRadioButton) {}
9270
addClass(className: string) {
9371
return this._delegate.setClass(className, true);
9472
}
@@ -103,7 +81,6 @@ class RadioAdapter implements MDCRadioAdapter {
10381
}
10482
}
10583

106-
const _singletonRadioAdapter = RadioAdapter.getAdapter();
10784

10885
/**
10986
* A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
@@ -152,11 +129,12 @@ export class MatRadioGroup extends _MatRadioGroupBase<MatRadioButton> {
152129
})
153130
export class MatRadioButton extends _MatRadioButtonBase implements AfterViewInit, OnDestroy {
154131

132+
private _radioAdapter: MDCRadioAdapter;
155133

156134
/** Configuration for the underlying ripple. */
157135
_rippleAnimation: RippleAnimationConfig = RIPPLE_ANIMATION_CONFIG;
158136

159-
_radioFoundation = new MDCRadioFoundation(_singletonRadioAdapter.useDelegate(this));
137+
_radioFoundation: MDCRadioFoundation;
160138
_classes: {[key: string]: boolean} = {};
161139

162140
constructor(@Optional() @Inject(MAT_RADIO_GROUP) radioGroup: MatRadioGroup,
@@ -169,6 +147,8 @@ export class MatRadioButton extends _MatRadioButtonBase implements AfterViewInit
169147
_providerOverride?: MatRadioDefaultOptions) {
170148
super(radioGroup, elementRef, _changeDetector, _focusMonitor,
171149
_radioDispatcher, _animationMode, _providerOverride);
150+
this._radioAdapter = new RadioAdapter(this);
151+
this._radioFoundation = new MDCRadioFoundation(this._radioAdapter);
172152
}
173153

174154
ngAfterViewInit() {

0 commit comments

Comments
 (0)