Skip to content

feat(material-experimental/mdc-slider): add support for rtl/ltr toggle #22196

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

Merged
merged 2 commits into from
Mar 11, 2021
Merged
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
17 changes: 15 additions & 2 deletions src/material-experimental/mdc-slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directionality} from '@angular/cdk/bidi';
import {
BooleanInput,
coerceBooleanProperty,
Expand All @@ -29,6 +30,7 @@ import {
NgZone,
OnDestroy,
OnInit,
Optional,
Output,
QueryList,
ViewChild,
Expand All @@ -46,6 +48,7 @@ import {
} from '@angular/material/core';
import {SpecificEventListener, EventType} from '@material/base';
import {MDCSliderAdapter, MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
import {Subscription} from 'rxjs';

/** Represents a drag event emitted by the MatSlider component. */
export interface MatSliderDragEvent {
Expand Down Expand Up @@ -582,14 +585,19 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
/** The display value of the end thumb. */
_endValueIndicatorText: string;

/** Subscription to changes to the directionality (LTR / RTL) context for the application. */
private _dirChangeSubscription: Subscription;

constructor(
readonly _cdr: ChangeDetectorRef,
readonly _elementRef: ElementRef<HTMLElement>,
private readonly _platform: Platform,
@Optional() private _dir: Directionality,
@Inject(DOCUMENT) document: any) {
super(_elementRef);
this._document = document;
this._window = this._document.defaultView || window;
this._dirChangeSubscription = this._dir.change.subscribe(() => this._reinitialize());
}

ngAfterViewInit() {
Expand Down Expand Up @@ -622,6 +630,12 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
if (this._platform.isBrowser) {
this._foundation.destroy();
}
this._dirChangeSubscription.unsubscribe();
}

/** Returns true if the language direction for this slider element is right to left. */
_isRTL() {
return this._dir && this._dir.value === 'rtl';
}

/**
Expand Down Expand Up @@ -777,8 +791,7 @@ class SliderAdapter implements MDCSliderAdapter {
return this._delegate._elementRef.nativeElement.getBoundingClientRect();
}
isRTL = (): boolean => {
// TODO(wagnermaciel): Actually implementing this.
return false;
return this._delegate._isRTL();
}
setThumbStyleProperty = (propertyName: string, value: string, thumbPosition: Thumb): void => {
this._delegate._getThumbElement(thumbPosition).style.setProperty(propertyName, value);
Expand Down