fix(progress-spinner): element size not updated when diamater is changed (#8697)

This commit is contained in:
André Roggeri Campos
2018-01-23 14:18:03 -02:00
committed by Jeremy Elbourn
parent f213f6cb97
commit 6d4c7ae714
2 changed files with 15 additions and 1 deletions
@@ -224,6 +224,14 @@ describe('MatProgressSpinner', () => {
expect(svgElement.getAttribute('viewBox')).toBe('0 0 38 38');
});
it('should update the element size when changed dynamically', () => {
let fixture = TestBed.createComponent(BasicProgressSpinner);
let spinner = fixture.debugElement.query(By.directive(MatProgressSpinner));
spinner.componentInstance.diameter = 32;
fixture.detectChanges();
expect(spinner.nativeElement.style.width).toBe('32px');
expect(spinner.nativeElement.style.height).toBe('32px');
});
});
+7 -1
View File
@@ -120,6 +120,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
if (!this._fallbackAnimation && !MatProgressSpinner.diameters.has(this._diameter)) {
this._attachStyleNode();
}
this._updateElementSize();
}
private _diameter = BASE_SIZE;
@@ -162,7 +163,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
ngOnChanges(changes: SimpleChanges) {
if (changes.strokeWidth || changes.diameter) {
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
this._updateElementSize();
}
}
@@ -226,6 +227,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
.replace(/DIAMETER/g, `${this.diameter}`);
}
/** Updates the spinner element size based on its diameter. */
private _updateElementSize() {
this._elementSize = this._diameter + Math.max(this.strokeWidth - BASE_STROKE_WIDTH, 0);
}
}