@@ -150,7 +150,13 @@ export class MatSlider implements AfterViewInit, OnDestroy {
150
150
}
151
151
152
152
ngAfterViewInit ( ) {
153
- this . _validateInputs ( ) ;
153
+ if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
154
+ _validateInputs (
155
+ this . _isRange ( ) ,
156
+ this . _getInputElement ( Thumb . START ) ,
157
+ this . _getInputElement ( Thumb . END ) ,
158
+ ) ;
159
+ }
154
160
if ( this . _platform . isBrowser ) {
155
161
this . _foundation . init ( ) ;
156
162
this . _foundation . layout ( ) ;
@@ -164,31 +170,6 @@ export class MatSlider implements AfterViewInit, OnDestroy {
164
170
}
165
171
}
166
172
167
- /**
168
- * Ensures that there is not an invalid configuration for the slider thumb inputs.
169
- */
170
- _validateInputs ( ) : void {
171
- if ( this . _isRange ( ) ) {
172
- if ( ! this . _getInputElement ( Thumb . START ) . hasAttribute ( 'matSliderStartThumb' ) ) {
173
- this . _throwInvalidInputConfigurationError ( 'matSliderStartThumb' ) ;
174
- }
175
- if ( ! this . _getInputElement ( Thumb . END ) . hasAttribute ( 'matSliderEndThumb' ) ) {
176
- this . _throwInvalidInputConfigurationError ( 'matSliderEndThumb' ) ;
177
- }
178
- } else {
179
- if ( ! this . _getInputElement ( Thumb . END ) . hasAttribute ( 'matSliderThumb' ) ) {
180
- this . _throwInvalidInputConfigurationError ( 'matSliderThumb' ) ;
181
- }
182
- }
183
- }
184
-
185
- /** Gets the current value of given slider thumb. */
186
- _getValue ( thumb : Thumb ) : number {
187
- return thumb === Thumb . START
188
- ? this . _foundation . getValueStart ( )
189
- : this . _foundation . getValue ( ) ;
190
- }
191
-
192
173
/** Sets the value of a slider thumb. */
193
174
_setValue ( value : number , thumb : Thumb ) : void {
194
175
thumb === Thumb . START
@@ -203,7 +184,7 @@ export class MatSlider implements AfterViewInit, OnDestroy {
203
184
204
185
/** Gets the slider thumb input of the given thumb. */
205
186
_getInput ( thumb : Thumb ) : MatSliderThumb {
206
- return thumb === Thumb . END ? this . _inputs . get ( this . _inputs . length - 1 ) ! : this . _inputs . get ( 0 ) ! ;
187
+ return thumb === Thumb . END ? this . _inputs . last ! : this . _inputs . first ! ;
207
188
}
208
189
209
190
/** Gets the slider thumb HTML input element of the given thumb. */
@@ -213,35 +194,28 @@ export class MatSlider implements AfterViewInit, OnDestroy {
213
194
214
195
/** Gets the slider thumb HTML element of the given thumb. */
215
196
_getThumbElement ( thumb : Thumb ) : HTMLElement {
216
- const thumbs = this . _thumbs . toArray ( ) . map ( e => e . nativeElement ) ;
217
- return thumb === Thumb . END ? thumbs [ thumbs . length - 1 ] : thumbs [ 0 ] ;
197
+ const thumbElementRef = thumb === Thumb . END ? this . _thumbs . last : this . _thumbs . first ;
198
+ return thumbElementRef . nativeElement ;
218
199
}
219
200
220
201
/** Gets the slider knob HTML element of the given thumb. */
221
202
_getKnobElement ( thumb : Thumb ) : HTMLElement {
222
- const knobs = this . _knobs . toArray ( ) . map ( e => e . nativeElement ) ;
223
- return thumb === Thumb . END ? knobs [ knobs . length - 1 ] : knobs [ 0 ] ;
203
+ const knobElementRef = thumb === Thumb . END ? this . _knobs . last : this . _knobs . first ;
204
+ return knobElementRef . nativeElement ;
224
205
}
225
206
226
- /** Gets the slider knob HTML element of the given thumb. */
227
- _getValueIndicatorTextElement ( thumb : Thumb ) : HTMLElement {
228
- const elements = this . _valueIndicatorTextElements . toArray ( ) . map ( e => e . nativeElement ) ;
229
- return thumb === Thumb . END ? elements [ elements . length - 1 ] : elements [ 0 ] ;
230
- }
231
-
232
207
/**
233
- * Gets the text representation of the given value.
208
+ * Sets the value indicator text of the given thumb using the given value.
234
209
*
235
- * Uses the `displayWith` function if one has been provided. Otherwise, it just returns the
236
- * current numeric value as a string.
210
+ * Uses the `displayWith` function if one has been provided. Otherwise, it just uses the
211
+ * numeric value as a string.
237
212
*/
238
- _getValueIndicatorText ( value : number ) : string {
239
- return this . displayWith ? this . displayWith ( value ) : `${ value } ` ;
240
- }
241
-
242
- /** Sets the value indicator text of the given thumb with the given value. */
243
213
_setValueIndicatorText ( value : number , thumb : Thumb ) : void {
244
- this . _getValueIndicatorTextElement ( thumb ) . textContent = this . _getValueIndicatorText ( value ) ;
214
+ const valueIndicatorTextElementRef = thumb === Thumb . END
215
+ ? this . _valueIndicatorTextElements . last
216
+ : this . _valueIndicatorTextElements . first ;
217
+ const valueText = this . displayWith ? this . displayWith ( value ) : `${ value } ` ;
218
+ valueIndicatorTextElementRef . nativeElement . textContent = valueText ;
245
219
}
246
220
247
221
/** Determines the class name for a HTML element. */
@@ -256,28 +230,49 @@ export class MatSlider implements AfterViewInit, OnDestroy {
256
230
return this . _isRange ( ) ? [ Thumb . START , Thumb . END ] : [ Thumb . END ] ;
257
231
}
258
232
259
- _throwInvalidInputConfigurationError ( missingSelector : string ) : void {
260
- throw Error ( `Invalid slider thumb input configuration! Missing a ${ missingSelector } .
261
-
262
- Valid configurations are as follows:
263
-
264
- <mat-slider>
265
- <input mat-slider-thumb>
266
- </mat-slider>
267
-
268
- or
269
-
270
- <mat-slider>
271
- <input matSliderStartThumb>
272
- <input matSliderEndThumb>
273
- </mat-slider>
274
- ` ) ;
275
- }
276
-
277
233
static ngAcceptInputType_disabled : BooleanInput ;
278
234
static ngAcceptInputType_discrete : BooleanInput ;
279
235
static ngAcceptInputType_showTickMarks : BooleanInput ;
280
236
static ngAcceptInputType_min : NumberInput ;
281
237
static ngAcceptInputType_max : NumberInput ;
282
238
static ngAcceptInputType_step : NumberInput ;
283
239
}
240
+
241
+ /**
242
+ * Ensures that there is not an invalid configuration for the slider thumb inputs.
243
+ */
244
+ function _validateInputs (
245
+ isRange : boolean ,
246
+ startInputElement : HTMLInputElement ,
247
+ endInputElement : HTMLInputElement ) : void {
248
+ if ( isRange ) {
249
+ if ( ! startInputElement ! . hasAttribute ( 'matSliderStartThumb' ) ) {
250
+ _throwInvalidInputConfigurationError ( ) ;
251
+ }
252
+ if ( ! endInputElement . hasAttribute ( 'matSliderEndThumb' ) ) {
253
+ _throwInvalidInputConfigurationError ( ) ;
254
+ }
255
+ } else {
256
+ if ( ! endInputElement . hasAttribute ( 'matSliderThumb' ) ) {
257
+ _throwInvalidInputConfigurationError ( ) ;
258
+ }
259
+ }
260
+ }
261
+
262
+ function _throwInvalidInputConfigurationError ( ) : void {
263
+ throw Error ( `Invalid slider thumb input configuration!
264
+
265
+ Valid configurations are as follows:
266
+
267
+ <mat-slider>
268
+ <input matSliderThumb>
269
+ </mat-slider>
270
+
271
+ or
272
+
273
+ <mat-slider>
274
+ <input matSliderStartThumb>
275
+ <input matSliderEndThumb>
276
+ </mat-slider>
277
+ ` ) ;
278
+ }
0 commit comments