Skip to content

Commit 110c5e4

Browse files
committed
(fix): Update the elementSize of progress-spinner dynamically
1 parent 60b0625 commit 110c5e4

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
@@ -122,6 +122,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
122122
if (!this._fallbackAnimation && !MatProgressSpinner.diameters.has(this._diameter)) {
123123
this._attachStyleNode();
124124
}
125+
this._updateElementSize();
125126
}
126127
private _diameter = BASE_SIZE;
127128

@@ -165,7 +166,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
165166

166167
ngOnChanges(changes: SimpleChanges) {
167168
if (changes.strokeWidth || changes.diameter) {
168-
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
169+
this._updateElementSize();
169170
}
170171
}
171172

@@ -229,6 +230,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
229230
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
230231
.replace(/DIAMETER/g, `${this.diameter}`);
231232
}
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+
}
232238
}
233239

234240

0 commit comments

Comments
 (0)