Skip to content

Commit 0884c0b

Browse files
authored
feat(material-experimental/mdc-slider): add support for rtl/ltr toggle (#22196)
* feat(material-experimental/mdc-slider): add support for rtl/ltr toggle * fixup! feat(material-experimental/mdc-slider): add support for rtl/ltr toggle
1 parent f3925a0 commit 0884c0b

File tree

1 file changed

+15
-2
lines changed
  • src/material-experimental/mdc-slider

1 file changed

+15
-2
lines changed

src/material-experimental/mdc-slider/slider.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Directionality} from '@angular/cdk/bidi';
910
import {
1011
BooleanInput,
1112
coerceBooleanProperty,
@@ -29,6 +30,7 @@ import {
2930
NgZone,
3031
OnDestroy,
3132
OnInit,
33+
Optional,
3234
Output,
3335
QueryList,
3436
ViewChild,
@@ -46,6 +48,7 @@ import {
4648
} from '@angular/material/core';
4749
import {SpecificEventListener, EventType} from '@material/base';
4850
import {MDCSliderAdapter, MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
51+
import {Subscription} from 'rxjs';
4952

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

588+
/** Subscription to changes to the directionality (LTR / RTL) context for the application. */
589+
private _dirChangeSubscription: Subscription;
590+
585591
constructor(
586592
readonly _cdr: ChangeDetectorRef,
587593
readonly _elementRef: ElementRef<HTMLElement>,
588594
private readonly _platform: Platform,
595+
@Optional() private _dir: Directionality,
589596
@Inject(DOCUMENT) document: any) {
590597
super(_elementRef);
591598
this._document = document;
592599
this._window = this._document.defaultView || window;
600+
this._dirChangeSubscription = this._dir.change.subscribe(() => this._reinitialize());
593601
}
594602

595603
ngAfterViewInit() {
@@ -622,6 +630,12 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
622630
if (this._platform.isBrowser) {
623631
this._foundation.destroy();
624632
}
633+
this._dirChangeSubscription.unsubscribe();
634+
}
635+
636+
/** Returns true if the language direction for this slider element is right to left. */
637+
_isRTL() {
638+
return this._dir && this._dir.value === 'rtl';
625639
}
626640

627641
/**
@@ -777,8 +791,7 @@ class SliderAdapter implements MDCSliderAdapter {
777791
return this._delegate._elementRef.nativeElement.getBoundingClientRect();
778792
}
779793
isRTL = (): boolean => {
780-
// TODO(wagnermaciel): Actually implementing this.
781-
return false;
794+
return this._delegate._isRTL();
782795
}
783796
setThumbStyleProperty = (propertyName: string, value: string, thumbPosition: Thumb): void => {
784797
this._delegate._getThumbElement(thumbPosition).style.setProperty(propertyName, value);

0 commit comments

Comments
 (0)