Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material-experimental/mdc-progress-bar): don't rely on JS to change directionality #22705

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/material-experimental/mdc-progress-bar/progress-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
// Explicitly set to `block` since the browser defaults custom elements to `inline`.
display: block;

// Inverts the progress bar horizontally in `query` mode.
&[mode='query'] {
transform: scaleX(-1);
}

&._mat-animation-noopable {
.mdc-linear-progress__buffer-dots,
.mdc-linear-progress__primary-bar,
Expand Down
19 changes: 6 additions & 13 deletions src/material-experimental/mdc-progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie

constructor(public _elementRef: ElementRef<HTMLElement>,
private _ngZone: NgZone,
@Optional() private _dir?: Directionality,
@Optional() dir?: Directionality,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
super(_elementRef);
this._isNoopAnimation = _animationMode === 'NoopAnimations';
if (_dir) {
this._dirChangeSubscription = _dir.change.subscribe(() => this._syncFoundation());
if (dir) {
this._dirChangeSubscription = dir.change.subscribe(() => {
this._syncFoundation();
this._foundation?.restartAnimation();
});
}
}

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

if (foundation) {
const direction = this._dir ? this._dir.value : 'ltr';
const mode = this.mode;

const reverse = direction === 'rtl' ? mode !== 'query' : mode === 'query';
const progressDirection = reverse ? 'rtl' : 'ltr';
const currentDirection = this._elementRef.nativeElement.getAttribute('dir');
if (currentDirection !== progressDirection) {
this._elementRef.nativeElement.setAttribute('dir', progressDirection);
foundation.restartAnimation();
}

foundation.setDeterminate(mode !== 'indeterminate' && mode !== 'query');

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