@@ -130,7 +130,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
130
130
*/
131
131
get translateX ( ) : number {
132
132
if ( this . _slider . min >= this . _slider . max ) {
133
- this . _translateX = 0 ;
133
+ this . _translateX = this . _tickMarkOffset ;
134
134
return this . _translateX ;
135
135
}
136
136
if ( this . _translateX === undefined ) {
@@ -216,6 +216,9 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
216
216
/** The radius of a native html slider's knob. */
217
217
_knobRadius : number = 8 ;
218
218
219
+ /** The distance in px from the start of the slider track to the first tick mark. */
220
+ _tickMarkOffset = 3 ;
221
+
219
222
/** Whether user's cursor is currently in a mouse down state on the input. */
220
223
_isActive : boolean = false ;
221
224
@@ -490,15 +493,22 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
490
493
}
491
494
492
495
_clamp ( v : number ) : number {
493
- return Math . max ( Math . min ( v , this . _slider . _cachedWidth ) , 0 ) ;
496
+ const min = this . _tickMarkOffset ;
497
+ const max = this . _slider . _cachedWidth - this . _tickMarkOffset ;
498
+ return Math . max ( Math . min ( v , max ) , min ) ;
494
499
}
495
500
496
501
_calcTranslateXByValue ( ) : number {
497
502
if ( this . _slider . _isRtl ) {
498
- return ( 1 - this . percentage ) * this . _slider . _cachedWidth ;
503
+ return (
504
+ ( 1 - this . percentage ) * ( this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ) +
505
+ this . _tickMarkOffset
506
+ ) ;
499
507
}
500
- const tickMarkOffset = 3 ; // The spaces before & after the start & end tick marks.
501
- return this . percentage * ( this . _slider . _cachedWidth - tickMarkOffset * 2 ) + tickMarkOffset ;
508
+ return (
509
+ this . percentage * ( this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ) +
510
+ this . _tickMarkOffset
511
+ ) ;
502
512
}
503
513
504
514
_calcTranslateXByPointerEvent ( event : PointerEvent ) : number {
@@ -509,19 +519,18 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
509
519
* Used to set the slider width to the correct
510
520
* dimensions while the user is dragging.
511
521
*/
512
- _updateWidthActive ( ) : void {
513
- this . _hostElement . style . padding = `0 ${ this . _slider . _inputPadding } px` ;
514
- this . _hostElement . style . width = `calc(100% + ${ this . _slider . _inputPadding } px)` ;
515
- }
522
+ _updateWidthActive ( ) : void { }
516
523
517
524
/**
518
525
* Sets the slider input to disproportionate dimensions to allow for touch
519
526
* events to be captured on touch devices.
520
527
*/
521
528
_updateWidthInactive ( ) : void {
522
- this . _hostElement . style . padding = '0px' ;
523
- this . _hostElement . style . width = 'calc(100% + 48px)' ;
524
- this . _hostElement . style . left = '-24px' ;
529
+ this . _hostElement . style . padding = `0 ${ this . _slider . _inputPadding } px` ;
530
+ this . _hostElement . style . width = `calc(100% + ${
531
+ this . _slider . _inputPadding - this . _tickMarkOffset * 2
532
+ } px)`;
533
+ this . _hostElement . style . left = `-${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
525
534
}
526
535
527
536
_updateThumbUIByValue ( options ?: { withAnimation : boolean } ) : void {
@@ -617,7 +626,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
617
626
if ( ! this . _isLeftThumb && sibling ) {
618
627
return sibling . translateX ;
619
628
}
620
- return 0 ;
629
+ return this . _tickMarkOffset ;
621
630
}
622
631
623
632
/**
@@ -629,7 +638,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
629
638
if ( this . _isLeftThumb && sibling ) {
630
639
return sibling . translateX ;
631
640
}
632
- return this . _slider . _cachedWidth ;
641
+ return this . _slider . _cachedWidth - this . _tickMarkOffset ;
633
642
}
634
643
635
644
_setIsLeftThumb ( ) : void {
@@ -725,7 +734,8 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
725
734
726
735
override _updateWidthActive ( ) : void {
727
736
const minWidth = this . _slider . _rippleRadius * 2 - this . _slider . _inputPadding * 2 ;
728
- const maxWidth = this . _slider . _cachedWidth + this . _slider . _inputPadding - minWidth ;
737
+ const maxWidth =
738
+ this . _slider . _cachedWidth + this . _slider . _inputPadding - minWidth - this . _tickMarkOffset * 2 ;
729
739
const percentage =
730
740
this . _slider . min < this . _slider . max
731
741
? ( this . max - this . min ) / ( this . _slider . max - this . _slider . min )
@@ -740,7 +750,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
740
750
if ( ! sibling ) {
741
751
return ;
742
752
}
743
- const maxWidth = this . _slider . _cachedWidth ;
753
+ const maxWidth = this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ;
744
754
const midValue = this . _isEndThumb
745
755
? this . value - ( this . value - sibling . value ) / 2
746
756
: this . value + ( sibling . value - this . value ) / 2 ;
@@ -768,11 +778,11 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
768
778
this . _hostElement . style . padding = '0px' ;
769
779
770
780
if ( this . _isLeftThumb ) {
771
- this . _hostElement . style . left = '-24px' ;
781
+ this . _hostElement . style . left = `- ${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
772
782
this . _hostElement . style . right = 'auto' ;
773
783
} else {
774
784
this . _hostElement . style . left = 'auto' ;
775
- this . _hostElement . style . right = '-24px' ;
785
+ this . _hostElement . style . right = `- ${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
776
786
}
777
787
}
778
788
0 commit comments