@@ -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 ( )
@@ -170,8 +172,7 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
170
172
// This needs to be called after content init because the value can be set to the min if the
171
173
// value itself isn't set. If this happens, the control value accessor needs to be updated.
172
174
this . _controlValueAccessorChangeFn ( this . value ) ;
173
- this . snapThumbToValue ( ) ;
174
- this . _updateTickSeparation ( ) ;
175
+ this . _initTicksAndSlider ( ) ;
175
176
}
176
177
177
178
/** TODO: internal */
@@ -265,14 +266,28 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
265
266
*/
266
267
snapThumbToValue ( ) {
267
268
this . updatePercentFromValue ( ) ;
268
- this . _renderer . updateThumbAndFillPosition ( this . _percent , this . _sliderDimensions . width ) ;
269
+ if ( this . _sliderDimensions ) {
270
+ this . _renderer . updateThumbAndFillPosition ( this . _percent , this . _sliderDimensions . width ) ;
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Initializes the tick and slider positions.
276
+ * @private
277
+ */
278
+ private _initTicksAndSlider ( ) {
279
+ this . snapThumbToValue ( ) ;
280
+ this . _updateTickSeparation ( ) ;
269
281
}
270
282
271
283
/**
272
284
* Calculates the separation in pixels of tick marks. If there is no tick interval or the interval
273
285
* is set to something other than a number or 'auto', nothing happens.
274
286
*/
275
287
private _updateTickSeparation ( ) {
288
+ if ( ! this . _sliderDimensions ) {
289
+ return ;
290
+ }
276
291
if ( this . _tickInterval == 'auto' ) {
277
292
this . _updateAutoTickSeparation ( ) ;
278
293
} else if ( Number ( this . _tickInterval ) ) {
@@ -425,8 +440,10 @@ export class SliderRenderer {
425
440
* Draws ticks onto the tick container.
426
441
*/
427
442
drawTicks ( tickSeparation : number ) {
443
+ let sliderTrackContainer =
444
+ < HTMLElement > this . _sliderElement . querySelector ( '.md-slider-track-container' ) ;
445
+ let tickContainerWidth = sliderTrackContainer . getBoundingClientRect ( ) . width ;
428
446
let tickContainer = < HTMLElement > this . _sliderElement . querySelector ( '.md-slider-tick-container' ) ;
429
- let tickContainerWidth = tickContainer . getBoundingClientRect ( ) . width ;
430
447
// An extra element for the last tick is needed because the linear gradient cannot be told to
431
448
// always draw a tick at the end of the gradient. To get around this, there is a second
432
449
// container for ticks that has a single tick mark on the very right edge.
@@ -444,6 +461,8 @@ export class SliderRenderer {
444
461
// separation), don't show it by decreasing the width of the tick container element.
445
462
if ( tickContainerWidth % tickSeparation < ( tickSeparation / 2 ) ) {
446
463
tickContainer . style . width = tickContainerWidth - tickSeparation + 'px' ;
464
+ } else {
465
+ tickContainer . style . width = '' ;
447
466
}
448
467
}
449
468
}
0 commit comments