Skip to content

Commit 6d4c7ae

Browse files
andreroggerijelbourn
authored andcommitted
fix(progress-spinner): element size not updated when diamater is changed (#8697)
1 parent f213f6c commit 6d4c7ae

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ describe('MatProgressSpinner', () => {
224224
expect(svgElement.getAttribute('viewBox')).toBe('0 0 38 38');
225225
});
226226

227+
it('should update the element size when changed dynamically', () => {
228+
let fixture = TestBed.createComponent(BasicProgressSpinner);
229+
let spinner = fixture.debugElement.query(By.directive(MatProgressSpinner));
230+
spinner.componentInstance.diameter = 32;
231+
fixture.detectChanges();
232+
expect(spinner.nativeElement.style.width).toBe('32px');
233+
expect(spinner.nativeElement.style.height).toBe('32px');
234+
});
227235
});
228236

229237

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
120120
if (!this._fallbackAnimation && !MatProgressSpinner.diameters.has(this._diameter)) {
121121
this._attachStyleNode();
122122
}
123+
this._updateElementSize();
123124
}
124125
private _diameter = BASE_SIZE;
125126

@@ -162,7 +163,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
162163

163164
ngOnChanges(changes: SimpleChanges) {
164165
if (changes.strokeWidth || changes.diameter) {
165-
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
166+
this._updateElementSize();
166167
}
167168
}
168169

@@ -226,6 +227,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
226227
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
227228
.replace(/DIAMETER/g, `${this.diameter}`);
228229
}
230+
231+
/** Updates the spinner element size based on its diameter. */
232+
private _updateElementSize() {
233+
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
234+
}
229235
}
230236

231237

0 commit comments

Comments
 (0)