Skip to content

Commit 2c11c0d

Browse files
authored
refactor(material-experimental/mdc-radio): remove adapter usage (#24925)
Removes the dependency on the MDC radio adapter from the radio button component.
1 parent 5d578ef commit 2c11c0d

File tree

2 files changed

+2
-43
lines changed

2 files changed

+2
-43
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="mdc-form-field" #formField
22
[class.mdc-form-field--align-end]="labelPosition == 'before'">
3-
<div class="mdc-radio" [ngClass]="_classes">
3+
<div class="mdc-radio" [class.mdc-radio--disabled]="disabled">
44
<!-- Render this element first so the input is on top. -->
55
<div class="mat-mdc-radio-touch-target" (click)="_onInputInteraction($event)"></div>
66
<input #input class="mdc-radio__native-control" type="radio"

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

+1-42
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {
10-
AfterViewInit,
1110
Attribute,
1211
ChangeDetectionStrategy,
1312
ChangeDetectorRef,
@@ -18,12 +17,10 @@ import {
1817
forwardRef,
1918
Inject,
2019
InjectionToken,
21-
OnDestroy,
2220
Optional,
2321
QueryList,
2422
ViewEncapsulation,
2523
} from '@angular/core';
26-
import {MDCRadioAdapter, MDCRadioFoundation} from '@material/radio';
2724
import {
2825
MAT_RADIO_DEFAULT_OPTIONS,
2926
_MatRadioButtonBase,
@@ -107,21 +104,7 @@ export class MatRadioGroup extends _MatRadioGroupBase<MatRadioButton> {
107104
encapsulation: ViewEncapsulation.None,
108105
changeDetection: ChangeDetectionStrategy.OnPush,
109106
})
110-
export class MatRadioButton extends _MatRadioButtonBase implements AfterViewInit, OnDestroy {
111-
private _radioAdapter: MDCRadioAdapter = {
112-
addClass: (className: string) => this._setClass(className, true),
113-
removeClass: (className: string) => this._setClass(className, false),
114-
setNativeControlDisabled: (disabled: boolean) => {
115-
if (this.disabled !== disabled) {
116-
this.disabled = disabled;
117-
this._changeDetector.markForCheck();
118-
}
119-
},
120-
};
121-
122-
_radioFoundation = new MDCRadioFoundation(this._radioAdapter);
123-
_classes: {[key: string]: boolean} = {};
124-
107+
export class MatRadioButton extends _MatRadioButtonBase {
125108
constructor(
126109
@Optional() @Inject(MAT_RADIO_GROUP) radioGroup: MatRadioGroup,
127110
elementRef: ElementRef,
@@ -145,28 +128,4 @@ export class MatRadioButton extends _MatRadioButtonBase implements AfterViewInit
145128
tabIndex,
146129
);
147130
}
148-
149-
override ngAfterViewInit() {
150-
super.ngAfterViewInit();
151-
this._radioFoundation.init();
152-
}
153-
154-
override ngOnDestroy() {
155-
super.ngOnDestroy();
156-
this._radioFoundation.destroy();
157-
}
158-
159-
private _setClass(cssClass: string, active: boolean) {
160-
this._classes = {...this._classes, [cssClass]: active};
161-
this._changeDetector.markForCheck();
162-
}
163-
164-
/**
165-
* Overrides the parent function so that the foundation can be set with the current
166-
* disabled state.
167-
*/
168-
protected override _setDisabled(value: boolean) {
169-
super._setDisabled(value);
170-
this._radioFoundation.setDisabled(this.disabled);
171-
}
172131
}

0 commit comments

Comments
 (0)