@@ -80,7 +80,7 @@ export class MatSliderThumb implements AfterViewInit {
80
80
/** The current value of this slider input. */
81
81
@Input ( )
82
82
get value ( ) : number {
83
- return coerceNumberProperty ( this . _elementRef . nativeElement . getAttribute ( 'value' ) ) ;
83
+ return coerceNumberProperty ( this . _hostElement . getAttribute ( 'value' ) ) ;
84
84
}
85
85
set value ( v : number ) {
86
86
const value = coerceNumberProperty ( v ) ;
@@ -91,7 +91,7 @@ export class MatSliderThumb implements AfterViewInit {
91
91
this . _slider . _setValue ( value , this . _thumbPosition ) ;
92
92
} else {
93
93
// Setup for the MDC foundation.
94
- this . _elementRef . nativeElement . setAttribute ( 'value' , `${ value } ` ) ;
94
+ this . _hostElement . setAttribute ( 'value' , `${ value } ` ) ;
95
95
}
96
96
}
97
97
@@ -114,36 +114,41 @@ export class MatSliderThumb implements AfterViewInit {
114
114
? Thumb . START
115
115
: Thumb . END ;
116
116
117
+ /** The injected document if available or fallback to the global document reference. */
117
118
private _document : Document ;
118
119
120
+ /** The host native HTML input element. */
121
+ _hostElement : HTMLInputElement ;
122
+
119
123
constructor (
120
124
@Inject ( DOCUMENT ) document : any ,
121
125
private readonly _slider : MatSlider ,
122
- readonly _elementRef : ElementRef < HTMLInputElement > ,
126
+ private readonly _elementRef : ElementRef < HTMLInputElement > ,
123
127
) {
124
128
this . _document = document ;
129
+ this . _hostElement = _elementRef . nativeElement ;
125
130
// By calling this in the constructor we guarantee that the sibling sliders initial value by
126
131
// has already been set by the time we reach ngAfterViewInit().
127
132
this . _initializeInputValueAttribute ( ) ;
128
133
}
129
134
130
135
ngAfterViewInit ( ) {
131
- this . _initializeInputMinMax ( ) ;
136
+ this . _initializeInputState ( ) ;
132
137
this . _initializeInputValueProperty ( ) ;
133
138
134
139
// Setup for the MDC foundation.
135
140
if ( this . _slider . disabled ) {
136
- this . _elementRef . nativeElement . disabled = true ;
141
+ this . _hostElement . disabled = true ;
137
142
}
138
143
}
139
144
140
145
/** Returns true if this slider input currently has focus. */
141
146
_isFocused ( ) : boolean {
142
- return this . _document . activeElement === this . _elementRef . nativeElement ;
147
+ return this . _document . activeElement === this . _hostElement ;
143
148
}
144
149
145
150
/**
146
- * Sets the min and max properties on the slider thumb input.
151
+ * Sets the min, max, and step properties on the slider thumb input.
147
152
*
148
153
* Must be called AFTER the sibling slider thumb input is guaranteed to have had its value
149
154
* attribute value set. For a range slider, the min and max of the slider thumb input depends on
@@ -155,15 +160,16 @@ export class MatSliderThumb implements AfterViewInit {
155
160
* instead be capped at either the default min or max.
156
161
*
157
162
*/
158
- private _initializeInputMinMax ( ) : void {
159
- const min = this . _elementRef . nativeElement . hasAttribute ( 'matSliderEndThumb' )
163
+ private _initializeInputState ( ) : void {
164
+ const min = this . _hostElement . hasAttribute ( 'matSliderEndThumb' )
160
165
? this . _slider . _getInput ( Thumb . START ) . value
161
166
: this . _slider . min ;
162
- const max = this . _elementRef . nativeElement . hasAttribute ( 'matSliderStartThumb' )
167
+ const max = this . _hostElement . hasAttribute ( 'matSliderStartThumb' )
163
168
? this . _slider . _getInput ( Thumb . END ) . value
164
169
: this . _slider . max ;
165
- this . _elementRef . nativeElement . min = `${ min } ` ;
166
- this . _elementRef . nativeElement . max = `${ max } ` ;
170
+ this . _hostElement . min = `${ min } ` ;
171
+ this . _hostElement . max = `${ max } ` ;
172
+ this . _hostElement . step = `${ this . _slider . step } ` ;
167
173
}
168
174
169
175
/**
@@ -175,7 +181,7 @@ export class MatSliderThumb implements AfterViewInit {
175
181
* instead be capped at either the default min or max.
176
182
*/
177
183
private _initializeInputValueProperty ( ) : void {
178
- this . _elementRef . nativeElement . value = `${ this . value } ` ;
184
+ this . _hostElement . value = `${ this . value } ` ;
179
185
}
180
186
181
187
/**
@@ -186,8 +192,8 @@ export class MatSliderThumb implements AfterViewInit {
186
192
*/
187
193
private _initializeInputValueAttribute ( ) : void {
188
194
// Only set the default value if an initial value has not already been provided.
189
- if ( ! this . _elementRef . nativeElement . hasAttribute ( 'value' ) ) {
190
- this . value = this . _elementRef . nativeElement . hasAttribute ( 'matSliderEndThumb' )
195
+ if ( ! this . _hostElement . hasAttribute ( 'value' ) ) {
196
+ this . value = this . _hostElement . hasAttribute ( 'matSliderEndThumb' )
191
197
? this . _slider . max
192
198
: this . _slider . min ;
193
199
}
@@ -369,7 +375,7 @@ export class MatSlider implements AfterViewInit, OnDestroy {
369
375
370
376
/** Gets the slider thumb HTML input element of the given thumb position. */
371
377
_getInputElement ( thumbPosition : Thumb ) : HTMLInputElement {
372
- return this . _getInput ( thumbPosition ) . _elementRef . nativeElement ;
378
+ return this . _getInput ( thumbPosition ) . _hostElement ;
373
379
}
374
380
375
381
/** Gets the slider thumb HTML element of the given thumb position. */
0 commit comments