@@ -41,6 +41,7 @@ import {
41
41
} from '@angular/material/core' ;
42
42
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
43
43
import { Subscription } from 'rxjs' ;
44
+ import { take } from 'rxjs/operators' ;
44
45
import {
45
46
_MatThumb ,
46
47
_MatTickMark ,
@@ -388,6 +389,8 @@ export class MatSlider
388
389
/** Whether the slider is rtl. */
389
390
_isRtl : boolean = false ;
390
391
392
+ private _hasViewInitialized : boolean = false ;
393
+
391
394
/**
392
395
* The width of the tick mark track.
393
396
* The tick mark track width is different from full track width
@@ -425,9 +428,11 @@ export class MatSlider
425
428
if ( this . _platform . isBrowser ) {
426
429
this . _updateDimensions ( ) ;
427
430
}
431
+
428
432
const eInput = this . _getInput ( _MatThumb . END ) ;
429
433
const sInput = this . _getInput ( _MatThumb . START ) ;
430
434
this . _isRange = ! ! eInput && ! ! sInput ;
435
+ this . _cdr . detectChanges ( ) ;
431
436
432
437
if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
433
438
_validateInputs (
@@ -439,22 +444,13 @@ export class MatSlider
439
444
440
445
const thumb = this . _getThumb ( _MatThumb . END ) ;
441
446
this . _rippleRadius = thumb . _ripple . radius ;
442
-
443
447
this . _inputPadding = this . _rippleRadius - this . _knobRadius ;
444
448
this . _inputOffset = this . _knobRadius ;
445
449
446
- if ( eInput ) {
447
- eInput . initProps ( ) ;
448
- eInput . initUI ( ) ;
449
- }
450
- if ( sInput ) {
451
- sInput . initProps ( ) ;
452
- sInput . initUI ( ) ;
453
- }
454
- if ( this . _isRange ) {
455
- ( eInput as _MatSliderRangeThumb ) . _updateMinMax ( ) ;
456
- ( sInput as _MatSliderRangeThumb ) . _updateMinMax ( ) ;
457
- }
450
+ this . _isRange
451
+ ? this . _initUIRange ( eInput as _MatSliderRangeThumb , sInput as _MatSliderRangeThumb )
452
+ : this . _initUINonRange ( eInput ! ) ;
453
+
458
454
this . _updateTrackUI ( eInput ! ) ;
459
455
this . _updateTickMarkUI ( ) ;
460
456
this . _updateTickMarkTrackUI ( ) ;
@@ -463,6 +459,38 @@ export class MatSlider
463
459
this . _cdr . detectChanges ( ) ;
464
460
}
465
461
462
+ private _initUINonRange ( eInput : _MatSliderThumb ) : void {
463
+ eInput . initProps ( ) ;
464
+ eInput . initUI ( ) ;
465
+
466
+ this . _updateValueIndicatorUI ( eInput ) ;
467
+
468
+ this . _hasViewInitialized = true ;
469
+ eInput . _updateThumbUIByValue ( ) ;
470
+ }
471
+
472
+ private _initUIRange ( eInput : _MatSliderRangeThumb , sInput : _MatSliderRangeThumb ) : void {
473
+ eInput . initProps ( ) ;
474
+ eInput . initUI ( ) ;
475
+
476
+ sInput . initProps ( ) ;
477
+ sInput . initUI ( ) ;
478
+
479
+ eInput . _updateMinMax ( ) ;
480
+ sInput . _updateMinMax ( ) ;
481
+
482
+ eInput . _updateStaticStyles ( ) ;
483
+ sInput . _updateStaticStyles ( ) ;
484
+
485
+ this . _updateValueIndicatorUI ( eInput ) ;
486
+ this . _updateValueIndicatorUI ( sInput ) ;
487
+
488
+ this . _hasViewInitialized = true ;
489
+
490
+ eInput . _updateThumbUIByValue ( ) ;
491
+ sInput . _updateThumbUIByValue ( ) ;
492
+ }
493
+
466
494
ngOnDestroy ( ) : void {
467
495
this . _dirChangeSubscription . unsubscribe ( ) ;
468
496
this . _resizeObserver ?. disconnect ( ) ;
@@ -555,10 +583,22 @@ export class MatSlider
555
583
transformOrigin : string ;
556
584
} ) : void {
557
585
const trackStyle = this . _trackActive . nativeElement . style ;
586
+ const animationOriginChanged =
587
+ styles . left !== trackStyle . left && styles . right !== trackStyle . right ;
588
+
558
589
trackStyle . left = styles . left ;
559
590
trackStyle . right = styles . right ;
560
- trackStyle . transform = styles . transform ;
561
591
trackStyle . transformOrigin = styles . transformOrigin ;
592
+
593
+ if ( animationOriginChanged ) {
594
+ this . _elementRef . nativeElement . classList . add ( 'mat-mdc-slider-disable-track-animation' ) ;
595
+ this . _ngZone . onStable . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
596
+ this . _elementRef . nativeElement . classList . remove ( 'mat-mdc-slider-disable-track-animation' ) ;
597
+ trackStyle . transform = styles . transform ;
598
+ } ) ;
599
+ } else {
600
+ trackStyle . transform = styles . transform ;
601
+ }
562
602
}
563
603
564
604
/** Returns the translateX positioning for a tick mark based on it's index. */
@@ -571,6 +611,10 @@ export class MatSlider
571
611
// Handlers for updating the slider ui.
572
612
573
613
_onTranslateXChange ( source : _MatSliderThumb ) : void {
614
+ if ( ! this . _hasViewInitialized ) {
615
+ return ;
616
+ }
617
+
574
618
this . _updateThumbUI ( source ) ;
575
619
this . _updateTrackUI ( source ) ;
576
620
this . _updateOverlappingThumbUI ( source as _MatSliderRangeThumb ) ;
@@ -580,23 +624,39 @@ export class MatSlider
580
624
input1 : _MatSliderRangeThumb ,
581
625
input2 : _MatSliderRangeThumb ,
582
626
) : void {
627
+ if ( ! this . _hasViewInitialized ) {
628
+ return ;
629
+ }
630
+
583
631
input1 . _updateThumbUIByValue ( ) ;
584
632
input2 . _updateThumbUIByValue ( ) ;
585
633
}
586
634
587
635
_onValueChange ( source : _MatSliderThumb ) : void {
636
+ if ( ! this . _hasViewInitialized ) {
637
+ return ;
638
+ }
639
+
588
640
this . _updateValueIndicatorUI ( source ) ;
589
641
this . _updateTickMarkUI ( ) ;
590
642
this . _cdr . detectChanges ( ) ;
591
643
}
592
644
593
645
_onMinMaxOrStepChange ( ) : void {
646
+ if ( ! this . _hasViewInitialized ) {
647
+ return ;
648
+ }
649
+
594
650
this . _updateTickMarkUI ( ) ;
595
651
this . _updateTickMarkTrackUI ( ) ;
596
652
this . _cdr . markForCheck ( ) ;
597
653
}
598
654
599
655
_onResize ( ) : void {
656
+ if ( ! this . _hasViewInitialized ) {
657
+ return ;
658
+ }
659
+
600
660
this . _updateDimensions ( ) ;
601
661
if ( this . _isRange ) {
602
662
const eInput = this . _getInput ( _MatThumb . END ) as _MatSliderRangeThumb ;
@@ -693,7 +753,11 @@ export class MatSlider
693
753
}
694
754
695
755
const valuetext = this . displayWith ( source . value ) ;
696
- source . _valuetext = valuetext ;
756
+
757
+ this . _hasViewInitialized
758
+ ? ( source . _valuetext = valuetext )
759
+ : source . _hostElement . setAttribute ( 'aria-valuetext' , valuetext ) ;
760
+
697
761
if ( this . discrete ) {
698
762
source . thumbPosition === _MatThumb . START
699
763
? ( this . startValueIndicatorText = valuetext )
0 commit comments