@@ -35,36 +35,13 @@ import {MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
35
35
import { SliderAdapter } from './slider-adapter' ;
36
36
import { MatSliderThumb } from './slider-thumb' ;
37
37
38
- /** A simple change event emitted by the MatSlider component. */
39
- export class MatSliderChange {
40
- /** The MatSlider that changed. */
41
- source : MatSlider ;
42
-
43
- /** The new value of the slider thumb that changed. */
44
- value : number ;
45
-
46
- /** The thumb that changed. */
47
- thumb : Thumb ;
48
-
49
- constructor ( source : MatSlider , value : number , thumb : Thumb ) {
50
- this . source = source ;
51
- this . value = value ;
52
- this . thumb = thumb ;
53
- }
54
- }
55
-
56
- /** A simple interaction event emitted by the MatSlider component. */
57
- export class MatSliderInteraction {
38
+ /** Represents an interaction event emitted by the MatSlider component. */
39
+ export interface MatSliderThumbInteractionEvent {
58
40
/** The MatSlider that was interacted with. */
59
41
source : MatSlider ;
60
42
61
43
/** The thumb that was interacted with. */
62
44
thumb : Thumb ;
63
-
64
- constructor ( source : MatSlider , thumb : Thumb ) {
65
- this . source = source ;
66
- this . thumb = thumb ;
67
- }
68
45
}
69
46
70
47
/**
@@ -78,9 +55,9 @@ export class MatSliderInteraction {
78
55
host : {
79
56
'class' : 'mat-mdc-slider mdc-slider' ,
80
57
'[class.mdc-slider--range]' : 'isRange' ,
81
- '[class.mdc-slider--disabled]' : 'isDisabled ' ,
82
- '[class.mdc-slider--discrete]' : 'isDiscrete ' ,
83
- '[class.mdc-slider--tick-marks]' : 'hasTickMarks ' ,
58
+ '[class.mdc-slider--disabled]' : 'disabled ' ,
59
+ '[class.mdc-slider--discrete]' : 'discrete ' ,
60
+ '[class.mdc-slider--tick-marks]' : 'showTickMarks ' ,
84
61
} ,
85
62
exportAs : 'matSlider' ,
86
63
changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -97,30 +74,32 @@ export class MatSlider implements AfterViewInit, OnDestroy {
97
74
@ViewChild ( 'trackActive' ) _trackActive : ElementRef < HTMLElement > ;
98
75
99
76
/** The sliders hidden range input(s). */
100
- @ContentChildren ( MatSliderThumb , { descendants : false } ) _inputs : QueryList < MatSliderThumb > ;
77
+ @ContentChildren ( MatSliderThumb , { descendants : false } ) _inputs : QueryList < MatSliderThumb > ;
101
78
102
79
/** Whether the slider is disabled. */
103
80
@Input ( )
104
- get isDisabled ( ) : boolean { return this . _isDisabled ; }
105
- set isDisabled ( v : boolean ) {
106
- this . _isDisabled = coerceBooleanProperty ( v ) ;
81
+ get disabled ( ) : boolean { return this . _disabled ; }
82
+ set disabled ( v : boolean ) {
83
+ this . _disabled = coerceBooleanProperty ( v ) ;
107
84
if ( this . _initialized ) {
108
85
this . _foundation . setDisabled ( v ) ;
109
86
}
110
87
}
111
- private _isDisabled : boolean = false ;
88
+ private _disabled : boolean = false ;
112
89
113
90
/** Whether the slider displays a numeric value label upon pressing the thumb. */
114
91
@Input ( )
115
- get isDiscrete ( ) : boolean { return this . _isDiscrete ; }
116
- set isDiscrete ( v : boolean ) { this . _isDiscrete = coerceBooleanProperty ( v ) ; }
117
- private _isDiscrete : boolean = false ;
92
+ get discrete ( ) : boolean { return this . _discrete ; }
93
+ set discrete ( v : boolean ) { this . _discrete = coerceBooleanProperty ( v ) ; }
94
+ private _discrete : boolean = false ;
118
95
119
96
/** Whether the slider displays tick marks along the slider track. */
120
97
@Input ( )
121
- get hasTickMarks ( ) : boolean { return this . _hasTickMarks ; }
122
- set hasTickMarks ( v : boolean ) { this . _hasTickMarks = coerceBooleanProperty ( this . _hasTickMarks ) ; }
123
- private _hasTickMarks : boolean = false ;
98
+ get showTickMarks ( ) : boolean { return this . _showTickMarks ; }
99
+ set showTickMarks ( v : boolean ) {
100
+ this . _showTickMarks = coerceBooleanProperty ( this . _showTickMarks ) ;
101
+ }
102
+ private _showTickMarks : boolean = false ;
124
103
125
104
/** The minimum value that the slider can have. */
126
105
@Input ( )
@@ -147,19 +126,13 @@ export class MatSlider implements AfterViewInit, OnDestroy {
147
126
*/
148
127
@Input ( ) displayWith : ( ( value : number ) => string ) | null ;
149
128
150
- /** Event emitted when a slider thumb value has changed. */
151
- @Output ( ) readonly change : EventEmitter < MatSliderChange > = new EventEmitter < MatSliderChange > ( ) ;
152
-
153
- /** Event emitted when a slider thumb moves. */
154
- @Output ( ) readonly input : EventEmitter < MatSliderChange > = new EventEmitter < MatSliderChange > ( ) ;
155
-
156
129
/** Event emitted when the slider thumb starts being dragged. */
157
- @Output ( ) readonly dragStart : EventEmitter < MatSliderInteraction >
158
- = new EventEmitter < MatSliderInteraction > ( ) ;
130
+ @Output ( ) readonly dragStart : EventEmitter < MatSliderThumbInteractionEvent >
131
+ = new EventEmitter < MatSliderThumbInteractionEvent > ( ) ;
159
132
160
133
/** Event emitted when the slider thumb stops being dragged. */
161
- @Output ( ) readonly dragEnd : EventEmitter < MatSliderInteraction >
162
- = new EventEmitter < MatSliderInteraction > ( ) ;
134
+ @Output ( ) readonly dragEnd : EventEmitter < MatSliderThumbInteractionEvent >
135
+ = new EventEmitter < MatSliderThumbInteractionEvent > ( ) ;
163
136
164
137
/** Whether this is a ranged slider. */
165
138
get isRange ( ) : boolean { return this . _inputs . length === 2 ; }
@@ -176,6 +149,18 @@ export class MatSlider implements AfterViewInit, OnDestroy {
176
149
/** The string representation of the end thumbs value. */
177
150
_endValueIndicatorText : string ;
178
151
152
+ /** The injected document if available or fallback to the global document reference. */
153
+ _document : Document ;
154
+
155
+ /**
156
+ * The defaultView of the injected document if
157
+ * available or fallback to global window reference.
158
+ */
159
+ _window : Window ;
160
+
161
+ /** The hosts native HTML element. */
162
+ _hostElement : HTMLElement ;
163
+
179
164
/** Used to keep track of & render the active & inactive tick marks on the slider track. */
180
165
get tickMarks ( ) : TickMark [ ] { return this . _tickMarks ; }
181
166
set tickMarks ( v : TickMark [ ] ) {
@@ -188,7 +173,11 @@ export class MatSlider implements AfterViewInit, OnDestroy {
188
173
private _cdr : ChangeDetectorRef ,
189
174
private readonly _elementRef : ElementRef < HTMLElement > ,
190
175
private readonly _platform : Platform ,
191
- @Inject ( DOCUMENT ) private readonly _document : any ) { }
176
+ @Inject ( DOCUMENT ) protected readonly document : any ) {
177
+ this . _document = this . document ;
178
+ this . _window = this . _document . defaultView || window ;
179
+ this . _hostElement = this . _elementRef . nativeElement ;
180
+ }
192
181
193
182
ngAfterViewInit ( ) {
194
183
this . _foundation . init ( ) ;
@@ -217,32 +206,14 @@ export class MatSlider implements AfterViewInit, OnDestroy {
217
206
: this . _foundation . setValue ( value ) ;
218
207
}
219
208
220
- /** Returns the injected document if available or fallback to the global document reference. */
221
- _getDocument ( ) : Document {
222
- return this . _document || document ;
223
- }
224
-
225
- /**
226
- * Returns the defaultView of the injected document
227
- * if available or fallback to global window reference.
228
- */
229
- _getWindow ( ) : Window {
230
- return this . _document . defaultView || window ;
231
- }
232
-
233
- /** Gets the hosts native HTML element. */
234
- _getHostElement ( ) : HTMLElement {
235
- return this . _elementRef . nativeElement ;
236
- }
237
-
238
209
/** Gets the slider thumb input of the given thumb. */
239
210
_getInput ( thumb : Thumb ) : MatSliderThumb {
240
211
return thumb === Thumb . END ? this . _inputs . get ( this . _inputs . length - 1 ) ! : this . _inputs . get ( 0 ) ! ;
241
212
}
242
213
243
214
/** Gets the slider thumb HTML input element of the given thumb. */
244
215
_getInputElement ( thumb : Thumb ) : HTMLInputElement {
245
- return this . _getInput ( thumb ) . _getHostElement ( ) ;
216
+ return this . _getInput ( thumb ) . _hostElement ;
246
217
}
247
218
248
219
/** Gets the slider thumb HTML element of the given thumb. */
@@ -284,19 +255,14 @@ export class MatSlider implements AfterViewInit, OnDestroy {
284
255
return this . isRange ? [ Thumb . START , Thumb . END ] : [ Thumb . END ] ;
285
256
}
286
257
287
- /** Creates a MatSliderChange event. */
288
- _createChangeEvent ( value : number , thumb : Thumb ) : MatSliderChange {
289
- return new MatSliderChange ( this , value , thumb ) ;
290
- }
291
-
292
258
/** Creates a MatSliderInteraction event. */
293
- _createInteractionEvent ( thumb : Thumb ) : MatSliderInteraction {
294
- return new MatSliderInteraction ( this , thumb ) ;
259
+ _createThumbInteractionEvent ( thumb : Thumb ) : MatSliderThumbInteractionEvent {
260
+ return { source : this , thumb} ;
295
261
}
296
262
297
- static ngAcceptInputType_isDisabled : BooleanInput ;
298
- static ngAcceptInputType_isDiscrete : BooleanInput ;
299
- static ngAcceptInputType_hasTickMarks : BooleanInput ;
263
+ static ngAcceptInputType_disabled : BooleanInput ;
264
+ static ngAcceptInputType_discrete : BooleanInput ;
265
+ static ngAcceptInputType_showTickMarks : BooleanInput ;
300
266
static ngAcceptInputType_min : NumberInput ;
301
267
static ngAcceptInputType_max : NumberInput ;
302
268
static ngAcceptInputType_step : NumberInput ;
0 commit comments