Skip to content

Commit b997353

Browse files
crisbetojosephperrott
authored andcommitted
fix(progress-spinner): default strokeWidth to 10% of the diameter (#7746)
Currently the default stroke of a spinner is always 10px which doesn't look great on anything that's smaller than the default. These changes switch it to be 10% of the circle's diameter.
1 parent 20b47d7 commit b997353

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

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

66

77
describe('MatProgressSpinner', () => {
@@ -80,6 +80,16 @@ describe('MatProgressSpinner', () => {
8080
expect(progressComponent.value).toBe(0);
8181
});
8282

83+
it('should default to a stroke width that is 10% of the diameter', () => {
84+
const fixture = TestBed.createComponent(ProgressSpinnerCustomDiameter);
85+
const spinner = fixture.debugElement.query(By.directive(MatProgressSpinner));
86+
87+
fixture.componentInstance.diameter = 67;
88+
fixture.detectChanges();
89+
90+
expect(spinner.componentInstance.strokeWidth).toBe(6.7);
91+
});
92+
8393
it('should allow a custom diameter', () => {
8494
const fixture = TestBed.createComponent(ProgressSpinnerCustomDiameter);
8595
const spinner = fixture.debugElement.query(By.css('mat-progress-spinner')).nativeElement;
@@ -97,7 +107,7 @@ describe('MatProgressSpinner', () => {
97107
expect(parseInt(svgElement.style.height))
98108
.toBe(32, 'Expected the custom diameter to be applied to the svg element height.');
99109
expect(svgElement.getAttribute('viewBox'))
100-
.toBe('0 0 32 32', 'Expected the custom diameter to be applied to the svg viewBox.');
110+
.toBe('0 0 25.2 25.2', 'Expected the custom diameter to be applied to the svg viewBox.');
101111
});
102112

103113
it('should allow a custom stroke width', () => {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import {CanColor, mixinColor} from '@angular/material/core';
2222
import {Platform} from '@angular/cdk/platform';
2323
import {DOCUMENT} from '@angular/common';
24+
import {coerceNumberProperty} from '@angular/cdk/coercion';
2425

2526
/** Possible mode for a progress spinner. */
2627
export type ProgressSpinnerMode = 'determinate' | 'indeterminate';
@@ -87,6 +88,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
8788
private readonly _baseSize = 100;
8889
private readonly _baseStrokeWidth = 10;
8990
private _fallbackAnimation = false;
91+
private _strokeWidth: number;
9092

9193
/** The width and height of the host element. Will grow with stroke width. **/
9294
_elementSize = this._baseSize;
@@ -112,7 +114,15 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
112114
_diameter = this._baseSize;
113115

114116
/** Stroke width of the progress spinner. */
115-
@Input() strokeWidth: number = 10;
117+
@Input()
118+
get strokeWidth(): number {
119+
return this._strokeWidth || this.diameter / 10;
120+
}
121+
122+
set strokeWidth(value: number) {
123+
this._strokeWidth = coerceNumberProperty(value);
124+
}
125+
116126

117127
/** Mode of the progress circle */
118128
@Input() mode: ProgressSpinnerMode = 'determinate';

0 commit comments

Comments
 (0)