Skip to content

Commit 4cf7716

Browse files
authored
fix(material-experimental/mdc-progress-bar): don't rely on JS to change directionality (#22705)
On the first iteration of the MDC progress bar we had to use JS to change the direction in RTL, but a few months ago in #21650 we switched to a different API that no longer depends on it. The problem with the changes in #21650 is that they set the `dir` on the progress bar in order to flip its direction for the `query` mode. These changes simplify the setup by relying only on CSS to determine the direction. Fixes #22609.
1 parent 7d53a6d commit 4cf7716

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/material-experimental/mdc-progress-bar/progress-bar.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
// Explicitly set to `block` since the browser defaults custom elements to `inline`.
88
display: block;
99

10+
// Inverts the progress bar horizontally in `query` mode.
11+
&[mode='query'] {
12+
transform: scaleX(-1);
13+
}
14+
1015
&._mat-animation-noopable {
1116
.mdc-linear-progress__buffer-dots,
1217
.mdc-linear-progress__primary-bar,

src/material-experimental/mdc-progress-bar/progress-bar.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
6969

7070
constructor(public _elementRef: ElementRef<HTMLElement>,
7171
private _ngZone: NgZone,
72-
@Optional() private _dir?: Directionality,
72+
@Optional() dir?: Directionality,
7373
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
7474
super(_elementRef);
7575
this._isNoopAnimation = _animationMode === 'NoopAnimations';
76-
if (_dir) {
77-
this._dirChangeSubscription = _dir.change.subscribe(() => this._syncFoundation());
76+
if (dir) {
77+
this._dirChangeSubscription = dir.change.subscribe(() => {
78+
this._syncFoundation();
79+
this._foundation?.restartAnimation();
80+
});
7881
}
7982
}
8083

@@ -218,17 +221,7 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
218221
const foundation = this._foundation;
219222

220223
if (foundation) {
221-
const direction = this._dir ? this._dir.value : 'ltr';
222224
const mode = this.mode;
223-
224-
const reverse = direction === 'rtl' ? mode !== 'query' : mode === 'query';
225-
const progressDirection = reverse ? 'rtl' : 'ltr';
226-
const currentDirection = this._elementRef.nativeElement.getAttribute('dir');
227-
if (currentDirection !== progressDirection) {
228-
this._elementRef.nativeElement.setAttribute('dir', progressDirection);
229-
foundation.restartAnimation();
230-
}
231-
232225
foundation.setDeterminate(mode !== 'indeterminate' && mode !== 'query');
233226

234227
// Divide by 100 because MDC deals with values between 0 and 1.

0 commit comments

Comments
 (0)