@@ -123,7 +123,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
123
123
*/
124
124
get translateX ( ) : number {
125
125
if ( this . _slider . min >= this . _slider . max ) {
126
- this . _translateX = 0 ;
126
+ this . _translateX = this . _tickMarkOffset ;
127
127
return this . _translateX ;
128
128
}
129
129
if ( this . _translateX === undefined ) {
@@ -209,6 +209,9 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
209
209
/** The radius of a native html slider's knob. */
210
210
_knobRadius : number = 8 ;
211
211
212
+ /** The distance in px from the start of the slider track to the first tick mark. */
213
+ _tickMarkOffset = 3 ;
214
+
212
215
/** Whether user's cursor is currently in a mouse down state on the input. */
213
216
_isActive : boolean = false ;
214
217
@@ -483,15 +486,22 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
483
486
}
484
487
485
488
_clamp ( v : number ) : number {
486
- return Math . max ( Math . min ( v , this . _slider . _cachedWidth ) , 0 ) ;
489
+ const min = this . _tickMarkOffset ;
490
+ const max = this . _slider . _cachedWidth - this . _tickMarkOffset ;
491
+ return Math . max ( Math . min ( v , max ) , min ) ;
487
492
}
488
493
489
494
_calcTranslateXByValue ( ) : number {
490
495
if ( this . _slider . _isRtl ) {
491
- return ( 1 - this . percentage ) * this . _slider . _cachedWidth ;
496
+ return (
497
+ ( 1 - this . percentage ) * ( this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ) +
498
+ this . _tickMarkOffset
499
+ ) ;
492
500
}
493
- const tickMarkOffset = 3 ; // The spaces before & after the start & end tick marks.
494
- return this . percentage * ( this . _slider . _cachedWidth - tickMarkOffset * 2 ) + tickMarkOffset ;
501
+ return (
502
+ this . percentage * ( this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ) +
503
+ this . _tickMarkOffset
504
+ ) ;
495
505
}
496
506
497
507
_calcTranslateXByPointerEvent ( event : PointerEvent ) : number {
@@ -502,19 +512,18 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
502
512
* Used to set the slider width to the correct
503
513
* dimensions while the user is dragging.
504
514
*/
505
- _updateWidthActive ( ) : void {
506
- this . _hostElement . style . padding = `0 ${ this . _slider . _inputPadding } px` ;
507
- this . _hostElement . style . width = `calc(100% + ${ this . _slider . _inputPadding } px)` ;
508
- }
515
+ _updateWidthActive ( ) : void { }
509
516
510
517
/**
511
518
* Sets the slider input to disproportionate dimensions to allow for touch
512
519
* events to be captured on touch devices.
513
520
*/
514
521
_updateWidthInactive ( ) : void {
515
- this . _hostElement . style . padding = '0px' ;
516
- this . _hostElement . style . width = 'calc(100% + 48px)' ;
517
- this . _hostElement . style . left = '-24px' ;
522
+ this . _hostElement . style . padding = `0 ${ this . _slider . _inputPadding } px` ;
523
+ this . _hostElement . style . width = `calc(100% + ${
524
+ this . _slider . _inputPadding - this . _tickMarkOffset * 2
525
+ } px)`;
526
+ this . _hostElement . style . left = `-${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
518
527
}
519
528
520
529
_updateThumbUIByValue ( options ?: { withAnimation : boolean } ) : void {
@@ -609,7 +618,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
609
618
if ( ! this . _isLeftThumb && sibling ) {
610
619
return sibling . translateX ;
611
620
}
612
- return 0 ;
621
+ return this . _tickMarkOffset ;
613
622
}
614
623
615
624
/**
@@ -621,7 +630,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
621
630
if ( this . _isLeftThumb && sibling ) {
622
631
return sibling . translateX ;
623
632
}
624
- return this . _slider . _cachedWidth ;
633
+ return this . _slider . _cachedWidth - this . _tickMarkOffset ;
625
634
}
626
635
627
636
_setIsLeftThumb ( ) : void {
@@ -717,7 +726,8 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
717
726
718
727
override _updateWidthActive ( ) : void {
719
728
const minWidth = this . _slider . _rippleRadius * 2 - this . _slider . _inputPadding * 2 ;
720
- const maxWidth = this . _slider . _cachedWidth + this . _slider . _inputPadding - minWidth ;
729
+ const maxWidth =
730
+ this . _slider . _cachedWidth + this . _slider . _inputPadding - minWidth - this . _tickMarkOffset * 2 ;
721
731
const percentage =
722
732
this . _slider . min < this . _slider . max
723
733
? ( this . max - this . min ) / ( this . _slider . max - this . _slider . min )
@@ -732,7 +742,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
732
742
if ( ! sibling ) {
733
743
return ;
734
744
}
735
- const maxWidth = this . _slider . _cachedWidth ;
745
+ const maxWidth = this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ;
736
746
const midValue = this . _isEndThumb
737
747
? this . value - ( this . value - sibling . value ) / 2
738
748
: this . value + ( sibling . value - this . value ) / 2 ;
@@ -760,11 +770,11 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
760
770
this . _hostElement . style . padding = '0px' ;
761
771
762
772
if ( this . _isLeftThumb ) {
763
- this . _hostElement . style . left = '-24px' ;
773
+ this . _hostElement . style . left = `- ${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
764
774
this . _hostElement . style . right = 'auto' ;
765
775
} else {
766
776
this . _hostElement . style . left = 'auto' ;
767
- this . _hostElement . style . right = '-24px' ;
777
+ this . _hostElement . style . right = `- ${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
768
778
}
769
779
}
770
780
0 commit comments