@@ -126,6 +126,7 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
126
126
if ( ! this . _isInitialized ) {
127
127
this . value = this . _min ;
128
128
}
129
+ this . _initTicksAndSlider ( ) ;
129
130
}
130
131
131
132
@Input ( )
@@ -136,6 +137,7 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
136
137
137
138
set max ( v : number ) {
138
139
this . _max = Number ( v ) ;
140
+ this . _initTicksAndSlider ( ) ;
139
141
}
140
142
141
143
@Input ( )
@@ -171,8 +173,7 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
171
173
// This needs to be called after content init because the value can be set to the min if the
172
174
// value itself isn't set. If this happens, the control value accessor needs to be updated.
173
175
this . _controlValueAccessorChangeFn ( this . value ) ;
174
- this . snapThumbToValue ( ) ;
175
- this . _updateTickSeparation ( ) ;
176
+ this . _initTicksAndSlider ( ) ;
176
177
}
177
178
178
179
/** TODO: internal */
@@ -271,11 +272,23 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
271
272
}
272
273
}
273
274
275
+ /**
276
+ * Initializes the tick and slider positions.
277
+ * @private
278
+ */
279
+ private _initTicksAndSlider ( ) {
280
+ this . snapThumbToValue ( ) ;
281
+ this . _updateTickSeparation ( ) ;
282
+ }
283
+
274
284
/**
275
285
* Calculates the separation in pixels of tick marks. If there is no tick interval or the interval
276
286
* is set to something other than a number or 'auto', nothing happens.
277
287
*/
278
288
private _updateTickSeparation ( ) {
289
+ if ( ! this . _sliderDimensions ) {
290
+ return ;
291
+ }
279
292
if ( this . _tickInterval == 'auto' ) {
280
293
this . _updateAutoTickSeparation ( ) ;
281
294
} else if ( Number ( this . _tickInterval ) ) {
@@ -428,8 +441,10 @@ export class SliderRenderer {
428
441
* Draws ticks onto the tick container.
429
442
*/
430
443
drawTicks ( tickSeparation : number ) {
444
+ let sliderTrackContainer =
445
+ < HTMLElement > this . _sliderElement . querySelector ( '.md-slider-track-container' ) ;
446
+ let tickContainerWidth = sliderTrackContainer . getBoundingClientRect ( ) . width ;
431
447
let tickContainer = < HTMLElement > this . _sliderElement . querySelector ( '.md-slider-tick-container' ) ;
432
- let tickContainerWidth = tickContainer . getBoundingClientRect ( ) . width ;
433
448
// An extra element for the last tick is needed because the linear gradient cannot be told to
434
449
// always draw a tick at the end of the gradient. To get around this, there is a second
435
450
// container for ticks that has a single tick mark on the very right edge.
@@ -447,6 +462,8 @@ export class SliderRenderer {
447
462
// separation), don't show it by decreasing the width of the tick container element.
448
463
if ( tickContainerWidth % tickSeparation < ( tickSeparation / 2 ) ) {
449
464
tickContainer . style . width = tickContainerWidth - tickSeparation + 'px' ;
465
+ } else {
466
+ tickContainer . style . width = '' ;
450
467
}
451
468
}
452
469
}
0 commit comments