Skip to content

Commit b66cf88

Browse files
authored
refactor(material-experimental/mdc-progress-spinner): remove MDC adapter usage (#24955)
Removes our usage of the MDC adapter from the MDC-based progress spinner component.
1 parent c543db5 commit b66cf88

File tree

2 files changed

+9
-84
lines changed

2 files changed

+9
-84
lines changed

src/material-experimental/mdc-progress-spinner/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ ng_module(
2626
"//src/material/progress-spinner",
2727
"@npm//@angular/common",
2828
"@npm//@angular/core",
29-
"@npm//@material/circular-progress",
3029
],
3130
)
3231

src/material-experimental/mdc-progress-spinner/progress-spinner.ts

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@
77
*/
88

99
import {
10-
AfterViewInit,
1110
ChangeDetectionStrategy,
1211
Component,
1312
ElementRef,
1413
Inject,
1514
Input,
16-
OnDestroy,
1715
Optional,
1816
ViewChild,
1917
ViewEncapsulation,
2018
} from '@angular/core';
21-
import {
22-
MDCCircularProgressAdapter,
23-
MDCCircularProgressFoundation,
24-
} from '@material/circular-progress';
2519
import {CanColor, mixinColor} from '@angular/material-experimental/mdc-core';
2620
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2721
import {
@@ -61,6 +55,7 @@ const BASE_STROKE_WIDTH = 10;
6155
// Note: there is a known issue with JAWS that does not read progressbar aria labels on FireFox
6256
'tabindex': '-1',
6357
'[class._mat-animation-noopable]': `_noopAnimations`,
58+
'[class.mdc-circular-progress--indeterminate]': 'mode === "indeterminate"',
6459
'[style.width.px]': 'diameter',
6560
'[style.height.px]': 'diameter',
6661
'[attr.aria-valuemin]': '0',
@@ -74,41 +69,13 @@ const BASE_STROKE_WIDTH = 10;
7469
changeDetection: ChangeDetectionStrategy.OnPush,
7570
encapsulation: ViewEncapsulation.None,
7671
})
77-
export class MatProgressSpinner
78-
extends _MatProgressSpinnerBase
79-
implements AfterViewInit, OnDestroy, CanColor
80-
{
72+
export class MatProgressSpinner extends _MatProgressSpinnerBase implements CanColor {
8173
/** Whether the _mat-animation-noopable class should be applied, disabling animations. */
8274
_noopAnimations: boolean;
8375

84-
/** Implements all of the logic of the MDC circular progress. */
85-
_foundation: MDCCircularProgressFoundation;
86-
8776
/** The element of the determinate spinner. */
8877
@ViewChild('determinateSpinner') _determinateCircle: ElementRef<HTMLElement>;
8978

90-
/** Adapter used by MDC to interact with the DOM. */
91-
// TODO: switch to class when MDC removes object spread in foundation
92-
// https://github.com/material-components/material-components-web/pull/6256
93-
private _adapter: MDCCircularProgressAdapter = {
94-
addClass: (className: string) => this._elementRef.nativeElement.classList.add(className),
95-
hasClass: (className: string) => this._elementRef.nativeElement.classList.contains(className),
96-
removeClass: (className: string) => this._elementRef.nativeElement.classList.remove(className),
97-
removeAttribute: (name: string) => this._elementRef.nativeElement.removeAttribute(name),
98-
setAttribute: (name, value) => {
99-
if (name !== 'aria-valuenow') {
100-
// MDC deals with values between 0 and 1 but Angular Material deals with values between
101-
// 0 and 100 so the aria-valuenow should be set through the attr binding in the host
102-
// instead of by the MDC adapter
103-
this._elementRef.nativeElement.setAttribute(name, value);
104-
}
105-
},
106-
getDeterminateCircleAttribute: (attributeName: string) =>
107-
this._determinateCircle.nativeElement.getAttribute(attributeName),
108-
setDeterminateCircleAttribute: (attributeName: string, value: string) =>
109-
this._determinateCircle.nativeElement.setAttribute(attributeName, value),
110-
};
111-
11279
constructor(
11380
elementRef: ElementRef<HTMLElement>,
11481
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode: string,
@@ -134,65 +101,47 @@ export class MatProgressSpinner
134101
}
135102
}
136103

137-
private _mode: ProgressSpinnerMode =
138-
this._elementRef.nativeElement.nodeName.toLowerCase() === 'mat-spinner'
139-
? 'indeterminate'
140-
: 'determinate';
141-
142104
/**
143105
* Mode of the progress bar.
144106
*
145107
* Input must be one of these values: determinate, indeterminate, buffer, query, defaults to
146108
* 'determinate'.
147109
* Mirrored to mode attribute.
148110
*/
149-
@Input()
150-
get mode(): ProgressSpinnerMode {
151-
return this._mode;
152-
}
153-
154-
set mode(value: ProgressSpinnerMode) {
155-
this._mode = value;
156-
this._syncFoundation();
157-
}
158-
159-
private _value = 0;
111+
@Input() mode: ProgressSpinnerMode =
112+
this._elementRef.nativeElement.nodeName.toLowerCase() === 'mat-spinner'
113+
? 'indeterminate'
114+
: 'determinate';
160115

161116
/** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */
162117
@Input()
163118
get value(): number {
164119
return this.mode === 'determinate' ? this._value : 0;
165120
}
166-
167121
set value(v: NumberInput) {
168122
this._value = Math.max(0, Math.min(100, coerceNumberProperty(v)));
169-
this._syncFoundation();
170123
}
171-
172-
private _diameter = BASE_SIZE;
124+
private _value = 0;
173125

174126
/** The diameter of the progress spinner (will set width and height of svg). */
175127
@Input()
176128
get diameter(): number {
177129
return this._diameter;
178130
}
179-
180131
set diameter(size: NumberInput) {
181132
this._diameter = coerceNumberProperty(size);
182-
this._syncFoundation();
183133
}
184-
185-
private _strokeWidth: number;
134+
private _diameter = BASE_SIZE;
186135

187136
/** Stroke width of the progress spinner. */
188137
@Input()
189138
get strokeWidth(): number {
190139
return this._strokeWidth ?? this.diameter / 10;
191140
}
192-
193141
set strokeWidth(value: NumberInput) {
194142
this._strokeWidth = coerceNumberProperty(value);
195143
}
144+
private _strokeWidth: number;
196145

197146
/** The radius of the spinner, adjusted for stroke width. */
198147
_circleRadius(): number {
@@ -222,29 +171,6 @@ export class MatProgressSpinner
222171
_circleStrokeWidth() {
223172
return (this.strokeWidth / this.diameter) * 100;
224173
}
225-
226-
ngAfterViewInit() {
227-
this._foundation = new MDCCircularProgressFoundation(this._adapter);
228-
this._foundation.init();
229-
this._syncFoundation();
230-
}
231-
232-
ngOnDestroy() {
233-
if (this._foundation) {
234-
this._foundation.destroy();
235-
}
236-
}
237-
238-
/** Syncs the state of the progress spinner with the MDC foundation. */
239-
private _syncFoundation() {
240-
const foundation = this._foundation;
241-
242-
if (foundation) {
243-
const mode = this.mode;
244-
foundation.setProgress(this.value / 100);
245-
foundation.setDeterminate(mode === 'determinate');
246-
}
247-
}
248174
}
249175

250176
/**

0 commit comments

Comments
 (0)