From b903ae16673959c00e56b552a5e2038a9d1ea43e Mon Sep 17 00:00:00 2001 From: crisbeto Date: Tue, 7 Nov 2017 08:06:40 +0000 Subject: [PATCH] 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. --- .../progress-spinner/progress-spinner.spec.ts | 30 +++++++++++++++++-- src/lib/progress-spinner/progress-spinner.ts | 4 +-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/lib/progress-spinner/progress-spinner.spec.ts b/src/lib/progress-spinner/progress-spinner.spec.ts index 5c9c758f69ab..2c5bce299b7a 100644 --- a/src/lib/progress-spinner/progress-spinner.spec.ts +++ b/src/lib/progress-spinner/progress-spinner.spec.ts @@ -58,6 +58,27 @@ describe('MatProgressSpinner', () => { expect(progressElement.componentInstance.value).toBe(0); }); + it('should retain the value if it updates while indeterminate', () => { + let fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode); + let progressElement = fixture.debugElement.query(By.css('mat-progress-spinner')); + + fixture.componentInstance.mode = 'determinate'; + fixture.detectChanges(); + expect(progressElement.componentInstance.value).toBe(50); + + fixture.componentInstance.mode = 'indeterminate'; + fixture.detectChanges(); + expect(progressElement.componentInstance.value).toBe(0); + + fixture.componentInstance.value = 75; + fixture.detectChanges(); + expect(progressElement.componentInstance.value).toBe(0); + + fixture.componentInstance.mode = 'determinate'; + fixture.detectChanges(); + expect(progressElement.componentInstance.value).toBe(75); + }); + it('should clamp the value of the progress between 0 and 100', () => { let fixture = TestBed.createComponent(BasicProgressSpinner); fixture.detectChanges(); @@ -222,8 +243,13 @@ class ProgressSpinnerCustomDiameter { @Component({template: ''}) class IndeterminateProgressSpinner { } -@Component({template: ''}) -class ProgressSpinnerWithValueAndBoundMode { mode = 'indeterminate'; } +@Component({ + template: '' +}) +class ProgressSpinnerWithValueAndBoundMode { + mode = 'indeterminate'; + value = 50; +} @Component({template: ``}) class SpinnerWithColor { color: string = 'primary'; } diff --git a/src/lib/progress-spinner/progress-spinner.ts b/src/lib/progress-spinner/progress-spinner.ts index c4db3d0016ef..bd33080b9d75 100644 --- a/src/lib/progress-spinner/progress-spinner.ts +++ b/src/lib/progress-spinner/progress-spinner.ts @@ -146,9 +146,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements return this.mode === 'determinate' ? this._value : 0; } set value(newValue: number) { - if (newValue != null && this.mode === 'determinate') { - this._value = Math.max(0, Math.min(100, coerceNumberProperty(newValue))); - } + this._value = Math.max(0, Math.min(100, coerceNumberProperty(newValue))); } constructor(public _renderer: Renderer2, public _elementRef: ElementRef,