@@ -285,7 +285,9 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
285285 /** The values at which the thumb will snap. */
286286 @Input ( { transform : numberAttribute } )
287287 get step ( ) : number {
288- return this . _step ;
288+ // A step of 0 is treated as "no step".
289+ // i.e. a slider which does not snap to any values.
290+ return this . _step < 0 ? 1 : this . _step ;
289291 }
290292 set step ( v : number ) {
291293 const step = isNaN ( v ) ? this . _step : v ;
@@ -592,12 +594,6 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
592594 }
593595
594596 /** Returns the translateX positioning for a tick mark based on it's index. */
595- _calcTickMarkTransform ( index : number ) : string {
596- // TODO(wagnermaciel): See if we can avoid doing this and just using flex to position these.
597- const offset = index * ( this . _tickMarkTrackWidth / ( this . _tickMarks . length - 1 ) ) ;
598- const translateX = this . _isRtl ( ) ? this . _cachedWidth - 6 - offset : offset ;
599- return `translateX(${ translateX } px)` ;
600- }
601597
602598 // Handlers for updating the slider ui.
603599
@@ -791,7 +787,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
791787 }
792788
793789 const step = this . _step && this . _step > 0 ? this . _step : 1 ;
794- const maxValue = Math . floor ( this . max / step ) * step ;
790+ const maxValue = this . min + Math . floor ( ( this . max - this . min ) / step ) * step ;
795791 const percentage = ( maxValue - this . min ) / ( this . max - this . min ) ;
796792 this . _tickMarkTrackWidth = ( this . _cachedWidth - 6 ) * percentage ;
797793 }
@@ -872,42 +868,30 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
872868
873869 /** Updates the dots along the slider track. */
874870 _updateTickMarkUI ( ) : void {
875- if (
876- ! this . showTickMarks ||
877- this . step === undefined ||
878- this . min === undefined ||
879- this . max === undefined
880- ) {
871+ if ( ! this . showTickMarks ) {
881872 return ;
882873 }
883- const step = this . step > 0 ? this . step : 1 ;
884- this . _isRange ? this . _updateTickMarkUIRange ( step ) : this . _updateTickMarkUINonRange ( step ) ;
885- }
886-
887- private _updateTickMarkUINonRange ( step : number ) : void {
888- const value = this . _getValue ( ) ;
889- let numActive = Math . max ( Math . round ( ( value - this . min ) / step ) , 0 ) + 1 ;
890- let numInactive = Math . max ( Math . round ( ( this . max - value ) / step ) , 0 ) - 1 ;
891- this . _isRtl ( ) ? numActive ++ : numInactive ++ ;
892874
893- this . _tickMarks = Array ( numActive )
894- . fill ( _MatTickMark . ACTIVE )
895- . concat ( Array ( numInactive ) . fill ( _MatTickMark . INACTIVE ) ) ;
896- }
897-
898- private _updateTickMarkUIRange ( step : number ) : void {
899- const endValue = this . _getValue ( ) ;
900- const startValue = this . _getValue ( _MatThumb . START ) ;
875+ const step = this . step || 1 ;
876+ const numTicks = Math . floor ( ( this . max - this . min ) / step ) + 1 ;
877+ this . _tickMarks = [ ] ;
901878
902- const numInactiveBeforeStartThumb = Math . max ( Math . round ( ( startValue - this . min ) / step ) , 0 ) ;
903- const numActive = Math . max ( Math . round ( ( endValue - startValue ) / step ) + 1 , 0 ) ;
904- const numInactiveAfterEndThumb = Math . max ( Math . round ( ( this . max - endValue ) / step ) , 0 ) ;
905- this . _tickMarks = Array ( numInactiveBeforeStartThumb )
906- . fill ( _MatTickMark . INACTIVE )
907- . concat (
908- Array ( numActive ) . fill ( _MatTickMark . ACTIVE ) ,
909- Array ( numInactiveAfterEndThumb ) . fill ( _MatTickMark . INACTIVE ) ,
910- ) ;
879+ if ( this . _isRange ) {
880+ const endValue = this . _getValue ( ) ;
881+ const startValue = this . _getValue ( _MatThumb . START ) ;
882+ for ( let i = 0 ; i < numTicks ; i ++ ) {
883+ const value = this . min + i * step ;
884+ const isActive = value >= startValue && value <= endValue ;
885+ this . _tickMarks . push ( isActive ? _MatTickMark . ACTIVE : _MatTickMark . INACTIVE ) ;
886+ }
887+ } else {
888+ const value = this . _getValue ( ) ;
889+ for ( let i = 0 ; i < numTicks ; i ++ ) {
890+ const v = this . min + i * step ;
891+ const isActive = v <= value ;
892+ this . _tickMarks . push ( isActive ? _MatTickMark . ACTIVE : _MatTickMark . INACTIVE ) ;
893+ }
894+ }
911895 }
912896
913897 /** Gets the slider thumb input of the given thumb position. */
0 commit comments