Skip to content

Commit f17e8cb

Browse files
committed
fix(progress-spinner): set spinner width to match diameter.
1 parent c05005a commit f17e8cb

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

src/lib/progress-spinner/progress-spinner.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
-->
77

88
<svg
9-
[style.width.px]="_elementSize"
10-
[style.height.px]="_elementSize"
9+
[style.width.px]="diameter"
10+
[style.height.px]="diameter"
1111
[attr.viewBox]="_viewBox"
1212
preserveAspectRatio="xMidYMid meet"
1313
focusable="false">

src/lib/progress-spinner/progress-spinner.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
ChangeDetectionStrategy,
1212
Input,
1313
ElementRef,
14-
SimpleChanges,
15-
OnChanges,
1614
ViewEncapsulation,
1715
Optional,
1816
Inject,
@@ -82,8 +80,8 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
8280
host: {
8381
'role': 'progressbar',
8482
'class': 'mat-progress-spinner',
85-
'[style.width.px]': '_elementSize',
86-
'[style.height.px]': '_elementSize',
83+
'[style.width.px]': 'diameter',
84+
'[style.height.px]': 'diameter',
8785
'[attr.aria-valuemin]': 'mode === "determinate" ? 0 : null',
8886
'[attr.aria-valuemax]': 'mode === "determinate" ? 100 : null',
8987
'[attr.aria-valuenow]': 'value',
@@ -95,16 +93,12 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
9593
changeDetection: ChangeDetectionStrategy.OnPush,
9694
encapsulation: ViewEncapsulation.None,
9795
})
98-
export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements CanColor,
99-
OnChanges {
96+
export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements CanColor {
10097

10198
private _value = 0;
10299
private _strokeWidth: number;
103100
private _fallbackAnimation = false;
104101

105-
/** The width and height of the host element. Will grow with stroke width. */
106-
_elementSize = BASE_SIZE;
107-
108102
/** Tracks diameters of existing instances to de-dupe generated styles (default d = 100) */
109103
private static diameters = new Set<number>([BASE_SIZE]);
110104

@@ -123,7 +117,6 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
123117
if (!this._fallbackAnimation && !MatProgressSpinner.diameters.has(this._diameter)) {
124118
this._attachStyleNode();
125119
}
126-
this._updateElementSize();
127120
}
128121
private _diameter = BASE_SIZE;
129122

@@ -164,12 +157,6 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
164157
_elementRef.nativeElement.classList.add(animationClass);
165158
}
166159

167-
ngOnChanges(changes: SimpleChanges) {
168-
if (changes.strokeWidth || changes.diameter) {
169-
this._updateElementSize();
170-
}
171-
}
172-
173160
/** The radius of the spinner, adjusted for stroke width. */
174161
get _circleRadius() {
175162
return (this.diameter - BASE_STROKE_WIDTH) / 2;
@@ -202,7 +189,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
202189

203190
/** Stroke width of the circle in percent. */
204191
get _circleStrokeWidth() {
205-
return this.strokeWidth / this._elementSize * 100;
192+
return this.strokeWidth / this.diameter * 100;
206193
}
207194

208195
/** Dynamically generates a style tag containing the correct animation for this diameter. */
@@ -230,11 +217,6 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
230217
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
231218
.replace(/DIAMETER/g, `${this.diameter}`);
232219
}
233-
234-
/** Updates the spinner element size based on its diameter. */
235-
private _updateElementSize() {
236-
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
237-
}
238220
}
239221

240222

@@ -251,8 +233,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
251233
'role': 'progressbar',
252234
'mode': 'indeterminate',
253235
'class': 'mat-spinner mat-progress-spinner',
254-
'[style.width.px]': '_elementSize',
255-
'[style.height.px]': '_elementSize',
236+
'[style.width.px]': 'diameter',
237+
'[style.height.px]': 'diameter',
256238
},
257239
inputs: ['color'],
258240
templateUrl: 'progress-spinner.html',

0 commit comments

Comments
 (0)