Skip to content

Commit d30ff10

Browse files
committed
fix(material/progress-spinner): fix setting diameter programmatically
1 parent 658b8fb commit d30ff10

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ describe('MDC-based MatProgressSpinner', () => {
123123
fixture.componentInstance.diameter = 32;
124124
fixture.detectChanges();
125125

126-
expect(parseInt(spinner.style.width))
126+
const {width, height} = spinner.getBoundingClientRect();
127+
128+
expect(width)
127129
.withContext('Expected the custom diameter to be applied to the host element width.')
128130
.toBe(32);
129-
expect(parseInt(spinner.style.height))
131+
expect(height)
130132
.withContext('Expected the custom diameter to be applied to the host element height.')
131133
.toBe(32);
132134
expect(parseInt(svgElement.clientWidth))
@@ -168,11 +170,12 @@ describe('MDC-based MatProgressSpinner', () => {
168170

169171
const spinner = fixture.debugElement.query(By.css('mat-progress-spinner'))!.nativeElement;
170172
const svgElement: HTMLElement = fixture.nativeElement.querySelector('svg');
173+
const {width, height} = spinner.getBoundingClientRect();
171174

172-
expect(parseFloat(spinner.style.width))
175+
expect(width)
173176
.withContext('Expected the custom diameter to be applied to the host element width.')
174177
.toBe(32.5);
175-
expect(parseFloat(spinner.style.height))
178+
expect(height)
176179
.withContext('Expected the custom diameter to be applied to the host element height.')
177180
.toBe(32.5);
178181
expect(Math.ceil(svgElement.clientWidth))
@@ -213,8 +216,10 @@ describe('MDC-based MatProgressSpinner', () => {
213216
fixture.componentInstance.strokeWidth = 40;
214217
fixture.detectChanges();
215218

216-
expect(element.style.width).toBe('100px');
217-
expect(element.style.height).toBe('100px');
219+
const {width, height} = element.getBoundingClientRect();
220+
221+
expect(width).toBe(100);
222+
expect(height).toBe(100);
218223
});
219224

220225
it('should not collapse the host element if the stroke width is less than the default', () => {
@@ -224,8 +229,10 @@ describe('MDC-based MatProgressSpinner', () => {
224229
fixture.componentInstance.strokeWidth = 5;
225230
fixture.detectChanges();
226231

227-
expect(element.style.width).toBe('100px');
228-
expect(element.style.height).toBe('100px');
232+
const {width, height} = element.getBoundingClientRect();
233+
234+
expect(width).toBe(100);
235+
expect(height).toBe(100);
229236
});
230237

231238
it('should set the color class on the mat-spinner', () => {
@@ -277,8 +284,10 @@ describe('MDC-based MatProgressSpinner', () => {
277284
expect(spinner.componentInstance.strokeWidth).toBe(11);
278285
expect(spinner.componentInstance.value).toBe(25);
279286

280-
expect(spinner.nativeElement.style.width).toBe('37px');
281-
expect(spinner.nativeElement.style.height).toBe('37px');
287+
const {width, height} = spinner.nativeElement.getBoundingClientRect();
288+
289+
expect(width).toBe(37);
290+
expect(height).toBe(37);
282291

283292
expect(svgElement.clientWidth).toBe(37);
284293
expect(svgElement.clientHeight).toBe(37);
@@ -290,8 +299,9 @@ describe('MDC-based MatProgressSpinner', () => {
290299
let spinner = fixture.debugElement.query(By.directive(MatProgressSpinner))!;
291300
spinner.componentInstance.diameter = 32;
292301
fixture.detectChanges();
293-
expect(spinner.nativeElement.style.width).toBe('32px');
294-
expect(spinner.nativeElement.style.height).toBe('32px');
302+
const {width, height} = spinner.nativeElement.getBoundingClientRect();
303+
expect(width).toBe(32);
304+
expect(height).toBe(32);
295305
});
296306

297307
it('should be able to set a default diameter', () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ const BASE_STROKE_WIDTH = 10;
8080
'tabindex': '-1',
8181
'[class._mat-animation-noopable]': `_noopAnimations`,
8282
'[class.mdc-circular-progress--indeterminate]': 'mode === "indeterminate"',
83-
'[style.width.px]': 'diameter',
84-
'[style.height.px]': 'diameter',
83+
'[style.--mdc-circular-progress-size]': 'diameter + "px"',
84+
'[style.--mdc-circular-progress-active-indicator-width]': 'diameter + "px"',
8585
'[attr.aria-valuemin]': '0',
8686
'[attr.aria-valuemax]': '100',
8787
'[attr.aria-valuenow]': 'mode === "determinate" ? value : null',

0 commit comments

Comments
 (0)