@@ -123,7 +123,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
123123 */
124124 get translateX ( ) : number {
125125 if ( this . _slider . min >= this . _slider . max ) {
126- this . _translateX = 0 ;
126+ this . _translateX = this . _tickMarkOffset ;
127127 return this . _translateX ;
128128 }
129129 if ( this . _translateX === undefined ) {
@@ -209,6 +209,9 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
209209 /** The radius of a native html slider's knob. */
210210 _knobRadius : number = 8 ;
211211
212+ /** The distance in px from the start of the slider track to the first tick mark. */
213+ _tickMarkOffset = 3 ;
214+
212215 /** Whether user's cursor is currently in a mouse down state on the input. */
213216 _isActive : boolean = false ;
214217
@@ -483,15 +486,22 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
483486 }
484487
485488 _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 ) ;
487492 }
488493
489494 _calcTranslateXByValue ( ) : number {
490495 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+ ) ;
492500 }
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+ ) ;
495505 }
496506
497507 _calcTranslateXByPointerEvent ( event : PointerEvent ) : number {
@@ -502,19 +512,18 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
502512 * Used to set the slider width to the correct
503513 * dimensions while the user is dragging.
504514 */
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 { }
509516
510517 /**
511518 * Sets the slider input to disproportionate dimensions to allow for touch
512519 * events to be captured on touch devices.
513520 */
514521 _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` ;
518527 }
519528
520529 _updateThumbUIByValue ( options ?: { withAnimation : boolean } ) : void {
@@ -609,7 +618,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
609618 if ( ! this . _isLeftThumb && sibling ) {
610619 return sibling . translateX ;
611620 }
612- return 0 ;
621+ return this . _tickMarkOffset ;
613622 }
614623
615624 /**
@@ -621,7 +630,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
621630 if ( this . _isLeftThumb && sibling ) {
622631 return sibling . translateX ;
623632 }
624- return this . _slider . _cachedWidth ;
633+ return this . _slider . _cachedWidth - this . _tickMarkOffset ;
625634 }
626635
627636 _setIsLeftThumb ( ) : void {
@@ -717,7 +726,8 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
717726
718727 override _updateWidthActive ( ) : void {
719728 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 ;
721731 const percentage =
722732 this . _slider . min < this . _slider . max
723733 ? ( this . max - this . min ) / ( this . _slider . max - this . _slider . min )
@@ -732,7 +742,7 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
732742 if ( ! sibling ) {
733743 return ;
734744 }
735- const maxWidth = this . _slider . _cachedWidth ;
745+ const maxWidth = this . _slider . _cachedWidth - this . _tickMarkOffset * 2 ;
736746 const midValue = this . _isEndThumb
737747 ? this . value - ( this . value - sibling . value ) / 2
738748 : this . value + ( sibling . value - this . value ) / 2 ;
@@ -760,11 +770,11 @@ export class MatSliderRangeThumb extends MatSliderThumb implements _MatSliderRan
760770 this . _hostElement . style . padding = '0px' ;
761771
762772 if ( this . _isLeftThumb ) {
763- this . _hostElement . style . left = '-24px' ;
773+ this . _hostElement . style . left = `- ${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
764774 this . _hostElement . style . right = 'auto' ;
765775 } else {
766776 this . _hostElement . style . left = 'auto' ;
767- this . _hostElement . style . right = '-24px' ;
777+ this . _hostElement . style . right = `- ${ this . _slider . _rippleRadius - this . _tickMarkOffset } px` ;
768778 }
769779 }
770780
0 commit comments