Skip to content

Commit

Permalink
fix(progress-spinner): element size not updated when diamater is chan…
Browse files Browse the repository at this point in the history
…ged (#8697)
  • Loading branch information
andreroggeri authored and jelbourn committed Jan 23, 2018
1 parent f213f6c commit 6d4c7ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/progress-spinner/progress-spinner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});


Expand Down
8 changes: 7 additions & 1 deletion src/lib/progress-spinner/progress-spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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);
}
}


Expand Down

0 comments on commit 6d4c7ae

Please sign in to comment.