99import { Directionality } from '@angular/cdk/bidi' ;
1010import { Platform } from '@angular/cdk/platform' ;
1111import {
12+ afterRenderEffect ,
1213 AfterViewInit ,
1314 booleanAttribute ,
1415 ChangeDetectionStrategy ,
1516 ChangeDetectorRef ,
1617 Component ,
18+ computed ,
1719 ContentChild ,
1820 ContentChildren ,
1921 ElementRef ,
@@ -34,7 +36,6 @@ import {
3436 RippleGlobalOptions ,
3537 ThemePalette ,
3638} from '../core' ;
37- import { Subscription } from 'rxjs' ;
3839import {
3940 _MatThumb ,
4041 _MatTickMark ,
@@ -372,9 +373,6 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
372373 /** Whether animations have been disabled. */
373374 _noopAnimations = _animationsDisabled ( ) ;
374375
375- /** Subscription to changes to the directionality (LTR / RTL) context for the application. */
376- private _dirChangeSubscription : Subscription | undefined ;
377-
378376 /** Observer used to monitor size changes in the slider. */
379377 private _resizeObserver : ResizeObserver | null = null ;
380378
@@ -401,7 +399,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
401399 _isRange : boolean = false ;
402400
403401 /** Whether the slider is rtl. */
404- _isRtl : boolean = false ;
402+ _isRtl = computed ( ( ) => this . _dir ?. valueSignal ( ) === 'rtl' ) ;
405403
406404 private _hasViewInitialized : boolean = false ;
407405
@@ -422,10 +420,19 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
422420 constructor ( ) {
423421 inject ( _CdkPrivateStyleLoader ) . load ( _StructuralStylesLoader ) ;
424422
425- if ( this . _dir ) {
426- this . _dirChangeSubscription = this . _dir . change . subscribe ( ( ) => this . _onDirChange ( ) ) ;
427- this . _isRtl = this . _dir . value === 'rtl' ;
428- }
423+ let prevIsRtl = this . _isRtl ( ) ;
424+
425+ afterRenderEffect ( ( ) => {
426+ const isRtl = this . _isRtl ( ) ;
427+
428+ // The diffing is normally handled by the signal, but we don't want to
429+ // fire on the first run, because it'll trigger unnecessary measurements.
430+ if ( isRtl !== prevIsRtl ) {
431+ prevIsRtl = isRtl ;
432+ this . _isRange ? this . _onDirChangeRange ( ) : this . _onDirChangeNonRange ( ) ;
433+ this . _updateTickMarkUI ( ) ;
434+ }
435+ } ) ;
429436 }
430437
431438 /** The radius of the native slider's knob. AFAIK there is no way to avoid hardcoding this. */
@@ -499,18 +506,10 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
499506 }
500507
501508 ngOnDestroy ( ) : void {
502- this . _dirChangeSubscription ?. unsubscribe ( ) ;
503509 this . _resizeObserver ?. disconnect ( ) ;
504510 this . _resizeObserver = null ;
505511 }
506512
507- /** Handles updating the slider ui after a dir change. */
508- private _onDirChange ( ) : void {
509- this . _isRtl = this . _dir ?. value === 'rtl' ;
510- this . _isRange ? this . _onDirChangeRange ( ) : this . _onDirChangeNonRange ( ) ;
511- this . _updateTickMarkUI ( ) ;
512- }
513-
514513 private _onDirChangeRange ( ) : void {
515514 const endInput = this . _getInput ( _MatThumb . END ) as _MatSliderRangeThumb ;
516515 const startInput = this . _getInput ( _MatThumb . START ) as _MatSliderRangeThumb ;
@@ -600,7 +599,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
600599 _calcTickMarkTransform ( index : number ) : string {
601600 // TODO(wagnermaciel): See if we can avoid doing this and just using flex to position these.
602601 const offset = index * ( this . _tickMarkTrackWidth / ( this . _tickMarks . length - 1 ) ) ;
603- const translateX = this . _isRtl ? this . _cachedWidth - 6 - offset : offset ;
602+ const translateX = this . _isRtl ( ) ? this . _cachedWidth - 6 - offset : offset ;
604603 return `translateX(${ translateX } px)` ;
605604 }
606605
@@ -852,7 +851,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
852851 }
853852
854853 private _updateTrackUINonRange ( source : _MatSliderThumb ) : void {
855- this . _isRtl
854+ this . _isRtl ( )
856855 ? this . _setTrackActiveStyles ( {
857856 left : 'auto' ,
858857 right : '0px' ,
@@ -893,7 +892,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
893892 const value = this . _getValue ( ) ;
894893 let numActive = Math . max ( Math . round ( ( value - this . min ) / step ) , 0 ) + 1 ;
895894 let numInactive = Math . max ( Math . round ( ( this . max - value ) / step ) , 0 ) - 1 ;
896- this . _isRtl ? numActive ++ : numInactive ++ ;
895+ this . _isRtl ( ) ? numActive ++ : numInactive ++ ;
897896
898897 this . _tickMarks = Array ( numActive )
899898 . fill ( _MatTickMark . ACTIVE )
0 commit comments