Skip to content

Commit c64cb7e

Browse files
fix(progress-spinner): set spinner width to match diameter. (#10314)
1 parent b3308de commit c64cb7e

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
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.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('MatProgressSpinner', () => {
140140
fixture.componentInstance.strokeWidth = 40;
141141
fixture.detectChanges();
142142

143-
expect(parseInt(circleElement.style.strokeWidth)).toBe(30, 'Expected the custom stroke ' +
143+
expect(parseInt(circleElement.style.strokeWidth)).toBe(40, 'Expected the custom stroke ' +
144144
'width to be applied to the circle element as a percentage of the element size.');
145145
expect(svgElement.getAttribute('viewBox'))
146146
.toBe('0 0 130 130', 'Expected the viewBox to be adjusted based on the stroke width.');
@@ -153,8 +153,8 @@ describe('MatProgressSpinner', () => {
153153
fixture.componentInstance.strokeWidth = 40;
154154
fixture.detectChanges();
155155

156-
expect(element.style.width).toBe('130px');
157-
expect(element.style.height).toBe('130px');
156+
expect(element.style.width).toBe('100px');
157+
expect(element.style.height).toBe('100px');
158158
});
159159

160160
it('should not collapse the host element if the stroke width is less than the default', () => {
@@ -217,10 +217,10 @@ describe('MatProgressSpinner', () => {
217217
expect(spinner.componentInstance.strokeWidth).toBe(11);
218218
expect(spinner.componentInstance.value).toBe(25);
219219

220-
expect(spinner.nativeElement.style.width).toBe('38px');
221-
expect(spinner.nativeElement.style.height).toBe('38px');
222-
expect(svgElement.style.width).toBe('38px');
223-
expect(svgElement.style.height).toBe('38px');
220+
expect(spinner.nativeElement.style.width).toBe('37px');
221+
expect(spinner.nativeElement.style.height).toBe('37px');
222+
expect(svgElement.style.width).toBe('37px');
223+
expect(svgElement.style.height).toBe('37px');
224224
expect(svgElement.getAttribute('viewBox')).toBe('0 0 38 38');
225225
});
226226

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)