mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(progress-spinner): inaccurate stroke width on really small spinners (#7725)
Fixes the spinner stroke not being accurate on really small spinners (<20px). This is follow-up from #7686.
This commit is contained in:
committed by
Andrew Seguin
parent
131e98f2ea
commit
f52f078924
@@ -9,9 +9,11 @@
|
||||
|
||||
<div class="demo-progress-spinner">
|
||||
<mat-progress-spinner [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
|
||||
[value]="progressValue" color="primary" [strokeWidth]="1" [diameter]="32"></mat-progress-spinner>
|
||||
[value]="progressValue" color="warn" [strokeWidth]="1.6" [diameter]="16"></mat-progress-spinner>
|
||||
<mat-progress-spinner [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
|
||||
[value]="progressValue" color="accent" [diameter]="50"></mat-progress-spinner>
|
||||
[value]="progressValue" color="accent" [strokeWidth]="1" [diameter]="32"></mat-progress-spinner>
|
||||
<mat-progress-spinner [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
|
||||
[value]="progressValue" color="primary" [diameter]="50"></mat-progress-spinner>
|
||||
</div>
|
||||
|
||||
<h1>Indeterminate</h1>
|
||||
|
||||
@@ -19,5 +19,5 @@
|
||||
[style.animation-name]="'mat-progress-spinner-stroke-rotate-' + diameter"
|
||||
[style.stroke-dashoffset.px]="_strokeDashOffset"
|
||||
[style.stroke-dasharray.px]="_strokeCircumference"
|
||||
[style.stroke-width.px]="strokeWidth"></circle>
|
||||
[style.stroke-width.%]="_circleStrokeWidth"></circle>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 772 B After Width: | Height: | Size: 778 B |
@@ -108,8 +108,8 @@ describe('MatProgressSpinner', () => {
|
||||
fixture.componentInstance.strokeWidth = 40;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(parseInt(circleElement.style.strokeWidth))
|
||||
.toBe(40, 'Expected the custom stroke width to be applied to the circle element.');
|
||||
expect(parseInt(circleElement.style.strokeWidth)).toBe(30, 'Expected the custom stroke ' +
|
||||
'width to be applied to the circle element as a percentage of the element size.');
|
||||
expect(svgElement.getAttribute('viewBox'))
|
||||
.toBe('0 0 130 130', 'Expected the viewBox to be adjusted based on the stroke width.');
|
||||
});
|
||||
|
||||
@@ -176,6 +176,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Stroke width of the circle in percent. */
|
||||
get _circleStrokeWidth() {
|
||||
return this.strokeWidth / this._elementSize * 100;
|
||||
}
|
||||
|
||||
/** Sets the diameter and adds diameter-specific styles if necessary. */
|
||||
private _setDiameterAndInitStyles(size: number): void {
|
||||
this._diameter = size;
|
||||
|
||||
Reference in New Issue
Block a user