Skip to content

Commit e40980c

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

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import {MatProgressSpinner, MatProgressSpinnerModule} from './index';
12
import {TestBed, async} from '@angular/core/testing';
2-
import {Component} from '@angular/core';
3-
import {By} from '@angular/platform-browser';
4-
import {MatProgressSpinnerModule, MatProgressSpinner} from './index';
53

4+
import {By} from '@angular/platform-browser';
5+
import {Component} from '@angular/core';
66

77
describe('MatProgressSpinner', () => {
88

@@ -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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {CanColor, mixinColor} from '@angular/material/core';
910
import {
10-
Component,
1111
ChangeDetectionStrategy,
12-
Input,
12+
Component,
1313
ElementRef,
14-
SimpleChanges,
14+
Inject,
15+
Input,
1516
OnChanges,
16-
ViewEncapsulation,
1717
Optional,
18-
Inject,
18+
SimpleChanges,
19+
ViewEncapsulation,
1920
} from '@angular/core';
20-
import {CanColor, mixinColor} from '@angular/material/core';
21-
import {Platform} from '@angular/cdk/platform';
21+
2222
import {DOCUMENT} from '@angular/common';
23+
import {Platform} from '@angular/cdk/platform';
2324
import {coerceNumberProperty} from '@angular/cdk/coercion';
2425

2526
/** Possible mode for a progress spinner. */
@@ -122,6 +123,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
122123
if (!this._fallbackAnimation && !MatProgressSpinner.diameters.has(this._diameter)) {
123124
this._attachStyleNode();
124125
}
126+
this._updateSpinnerDimension();
125127
}
126128
private _diameter = BASE_SIZE;
127129

@@ -165,7 +167,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
165167

166168
ngOnChanges(changes: SimpleChanges) {
167169
if (changes.strokeWidth || changes.diameter) {
168-
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
170+
this._updateSpinnerDimension();
169171
}
170172
}
171173

@@ -229,6 +231,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
229231
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
230232
.replace(/DIAMETER/g, `${this.diameter}`);
231233
}
234+
235+
/** Updates the spinner element size based on its diameter. */
236+
private _updateElementSize() {
237+
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
238+
}
232239
}
233240

234241

0 commit comments

Comments
 (0)