diff --git a/src/material/progress-bar/progress-bar.spec.ts b/src/material/progress-bar/progress-bar.spec.ts
index b465201c3e0f..9e33b463260a 100644
--- a/src/material/progress-bar/progress-bar.spec.ts
+++ b/src/material/progress-bar/progress-bar.spec.ts
@@ -183,6 +183,41 @@ describe('MatProgressBar', () => {
.toBe(false, 'Expect aria-valuenow to be cleared in query mode.');
});
+ it('should update the DOM transform when the value has changed', () => {
+ const fixture = createComponent(BasicProgressBar);
+ fixture.detectChanges();
+
+ const progressElement = fixture.debugElement.query(By.css('mat-progress-bar'))!;
+ const progressComponent = progressElement.componentInstance;
+ const primaryBar = progressElement.nativeElement.querySelector('.mat-progress-bar-primary');
+
+ expect(primaryBar.style.transform).toBe('scaleX(0)');
+
+ progressComponent.value = 40;
+ fixture.detectChanges();
+
+ expect(primaryBar.style.transform).toBe('scaleX(0.4)');
+ });
+
+ it('should update the DOM transform when the bufferValue has changed', () => {
+ const fixture = createComponent(BasicProgressBar);
+ fixture.detectChanges();
+
+ const progressElement = fixture.debugElement.query(By.css('mat-progress-bar'))!;
+ const progressComponent = progressElement.componentInstance;
+ const bufferBar = progressElement.nativeElement.querySelector('.mat-progress-bar-buffer');
+
+ progressComponent.mode = 'buffer';
+ fixture.detectChanges();
+
+ expect(bufferBar.style.transform).toBeFalsy();
+
+ progressComponent.bufferValue = 40;
+ fixture.detectChanges();
+
+ expect(bufferBar.style.transform).toBe('scaleX(0.4)');
+ });
+
});
describe('animation trigger on determinate setting', () => {
diff --git a/src/material/progress-bar/progress-bar.ts b/src/material/progress-bar/progress-bar.ts
index 1e60694f50b4..91b672cbaff8 100644
--- a/src/material/progress-bar/progress-bar.ts
+++ b/src/material/progress-bar/progress-bar.ts
@@ -23,6 +23,7 @@ import {
Output,
ViewChild,
ViewEncapsulation,
+ ChangeDetectorRef,
} from '@angular/core';
import {CanColor, CanColorCtor, mixinColor} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
@@ -111,16 +112,21 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
* @deprecated `location` parameter to be made required.
* @breaking-change 8.0.0
*/
- @Optional() @Inject(MAT_PROGRESS_BAR_LOCATION) location?: MatProgressBarLocation) {
+ @Optional() @Inject(MAT_PROGRESS_BAR_LOCATION) location?: MatProgressBarLocation,
+
+ /**
+ * @deprecated `_changeDetectorRef` parameter to be made required.
+ * @breaking-change 11.0.0
+ */
+ private _changeDetectorRef?: ChangeDetectorRef) {
super(_elementRef);
// We need to prefix the SVG reference with the current path, otherwise they won't work
// in Safari if the page has a `` tag. Note that we need quotes inside the `url()`,
-
- // because named route URLs can contain parentheses (see #12338). Also we don't use since
- // we can't tell the difference between whether
- // the consumer is using the hash location strategy or not, because `Location` normalizes
- // both `/#/foo/bar` and `/foo/bar` to the same thing.
+ // because named route URLs can contain parentheses (see #12338). Also we don't use `Location`
+ // since we can't tell the difference between whether the consumer is using the hash location
+ // strategy or not, because `Location` normalizes both `/#/foo/bar` and `/foo/bar` to
+ // the same thing.
const path = location ? location.getPathname().split('#')[0] : '';
this._rectangleFillValue = `url('${path}#${this.progressbarId}')`;
this._isNoopAnimation = _animationMode === 'NoopAnimations';
@@ -134,13 +140,21 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
get value(): number { return this._value; }
set value(v: number) {
this._value = clamp(coerceNumberProperty(v) || 0);
+
+ // @breaking-change 11.0.0 Remove null check for _changeDetectorRef.
+ this._changeDetectorRef?.markForCheck();
}
private _value: number = 0;
/** Buffer value of the progress bar. Defaults to zero. */
@Input()
get bufferValue(): number { return this._bufferValue; }
- set bufferValue(v: number) { this._bufferValue = clamp(v || 0); }
+ set bufferValue(v: number) {
+ this._bufferValue = clamp(v || 0);
+
+ // @breaking-change 11.0.0 Remove null check for _changeDetectorRef.
+ this._changeDetectorRef?.markForCheck();
+ }
private _bufferValue: number = 0;
@ViewChild('primaryValueBar') _primaryValueBar: ElementRef;
diff --git a/tools/public_api_guard/material/progress-bar.d.ts b/tools/public_api_guard/material/progress-bar.d.ts
index 9d79f8e76464..0f3e419a38ce 100644
--- a/tools/public_api_guard/material/progress-bar.d.ts
+++ b/tools/public_api_guard/material/progress-bar.d.ts
@@ -16,7 +16,8 @@ export declare class MatProgressBar extends _MatProgressBarMixinBase implements
get value(): number;
set value(v: number);
constructor(_elementRef: ElementRef, _ngZone: NgZone, _animationMode?: string | undefined,
- location?: MatProgressBarLocation);
+ location?: MatProgressBarLocation,
+ _changeDetectorRef?: ChangeDetectorRef | undefined);
_bufferTransform(): {
transform: string;
} | null;
@@ -27,7 +28,7 @@ export declare class MatProgressBar extends _MatProgressBarMixinBase implements
ngOnDestroy(): void;
static ngAcceptInputType_value: NumberInput;
static ɵcmp: i0.ɵɵComponentDefWithMeta;
- static ɵfac: i0.ɵɵFactoryDef;
+ static ɵfac: i0.ɵɵFactoryDef;
}
export interface MatProgressBarLocation {