Skip to content

Commit 5e91a4c

Browse files
committed
fix(progress-spinner): value not updated while in indeterminate mode
Fixes updates to a spinner's value not being saved if they happen while the component is indeterminate, causing it to be wrong if it becomes determinate again.
1 parent 262c23b commit 5e91a4c

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ describe('MatProgressSpinner', () => {
5858
expect(progressElement.componentInstance.value).toBe(0);
5959
});
6060

61+
it('should retain the value if it updates while indeterminate', () => {
62+
let fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);
63+
let progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'));
64+
65+
fixture.componentInstance.mode = 'determinate';
66+
fixture.detectChanges();
67+
expect(progressElement.componentInstance.value).toBe(50);
68+
69+
fixture.componentInstance.mode = 'indeterminate';
70+
fixture.detectChanges();
71+
expect(progressElement.componentInstance.value).toBe(0);
72+
73+
fixture.componentInstance.value = 75;
74+
fixture.detectChanges();
75+
expect(progressElement.componentInstance.value).toBe(0);
76+
77+
fixture.componentInstance.mode = 'determinate';
78+
fixture.detectChanges();
79+
expect(progressElement.componentInstance.value).toBe(75);
80+
});
81+
6182
it('should clamp the value of the progress between 0 and 100', () => {
6283
let fixture = TestBed.createComponent(BasicProgressSpinner);
6384
fixture.detectChanges();
@@ -222,8 +243,13 @@ class ProgressSpinnerCustomDiameter {
222243
@Component({template: '<mat-progress-spinner mode="indeterminate"></mat-progress-spinner>'})
223244
class IndeterminateProgressSpinner { }
224245

225-
@Component({template: '<mat-progress-spinner value="50" [mode]="mode"></mat-progress-spinner>'})
226-
class ProgressSpinnerWithValueAndBoundMode { mode = 'indeterminate'; }
246+
@Component({
247+
template: '<mat-progress-spinner [value]="value" [mode]="mode"></mat-progress-spinner>'
248+
})
249+
class ProgressSpinnerWithValueAndBoundMode {
250+
mode = 'indeterminate';
251+
value = 50;
252+
}
227253

228254
@Component({template: `<mat-spinner [color]="color"></mat-spinner>`})
229255
class SpinnerWithColor { color: string = 'primary'; }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
146146
return this.mode === 'determinate' ? this._value : 0;
147147
}
148148
set value(newValue: number) {
149-
if (newValue != null && this.mode === 'determinate') {
150-
this._value = Math.max(0, Math.min(100, coerceNumberProperty(newValue)));
151-
}
149+
this._value = Math.max(0, Math.min(100, coerceNumberProperty(newValue)));
152150
}
153151

154152
constructor(public _renderer: Renderer2, public _elementRef: ElementRef,

0 commit comments

Comments
 (0)