-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
slider.ts
708 lines (607 loc) · 23.1 KB
/
slider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {
Component,
ElementRef,
EventEmitter,
forwardRef,
Input,
OnDestroy,
Optional,
Output,
Renderer2,
ViewEncapsulation,
ChangeDetectionStrategy,
ChangeDetectorRef,
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {coerceBooleanProperty, coerceNumberProperty, HammerInput} from '../core';
import {Directionality} from '../core/bidi/index';
import {
DOWN_ARROW,
END,
HOME,
LEFT_ARROW,
PAGE_DOWN,
PAGE_UP,
RIGHT_ARROW,
UP_ARROW
} from '../core/keyboard/keycodes';
import {FocusOrigin, FocusOriginMonitor} from '../core/style/focus-origin-monitor';
import {mixinDisabled, CanDisable} from '../core/common-behaviors/disabled';
/**
* Visually, a 30px separation between tick marks looks best. This is very subjective but it is
* the default separation we chose.
*/
const MIN_AUTO_TICK_SEPARATION = 30;
/** The thumb gap size for a disabled slider. */
const DISABLED_THUMB_GAP = 7;
/** The thumb gap size for a non-active slider at its minimum value. */
const MIN_VALUE_NONACTIVE_THUMB_GAP = 7;
/** The thumb gap size for an active slider at its minimum value. */
const MIN_VALUE_ACTIVE_THUMB_GAP = 10;
/**
* Provider Expression that allows md-slider to register as a ControlValueAccessor.
* This allows it to support [(ngModel)] and [formControl].
*/
export const MD_SLIDER_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MdSlider),
multi: true
};
/** A simple change event emitted by the MdSlider component. */
export class MdSliderChange {
/** The MdSlider that changed. */
source: MdSlider;
/** The new value of the source slider. */
value: number | null;
}
// Boilerplate for applying mixins to MdSlider.
/** @docs-private */
export class MdSliderBase { }
export const _MdSliderMixinBase = mixinDisabled(MdSliderBase);
/**
* Allows users to select from a range of values by moving the slider thumb. It is similar in
* behavior to the native `<input type="range">` element.
*/
@Component({
moduleId: module.id,
selector: 'md-slider, mat-slider',
providers: [MD_SLIDER_VALUE_ACCESSOR],
host: {
'(focus)': '_onFocus()',
'(blur)': '_onBlur()',
'(click)': '_onClick($event)',
'(keydown)': '_onKeydown($event)',
'(keyup)': '_onKeyup()',
'(mouseenter)': '_onMouseenter()',
'(slide)': '_onSlide($event)',
'(slideend)': '_onSlideEnd()',
'(slidestart)': '_onSlideStart($event)',
'class': 'mat-slider',
'role': 'slider',
'tabindex': '0',
'[attr.aria-disabled]': 'disabled',
'[attr.aria-valuemax]': 'max',
'[attr.aria-valuemin]': 'min',
'[attr.aria-valuenow]': 'value',
'[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"',
'[class.mat-primary]': 'color == "primary"',
'[class.mat-accent]': 'color != "primary" && color != "warn"',
'[class.mat-warn]': 'color == "warn"',
'[class.mat-slider-disabled]': 'disabled',
'[class.mat-slider-has-ticks]': 'tickInterval',
'[class.mat-slider-horizontal]': '!vertical',
'[class.mat-slider-axis-inverted]': '_invertAxis',
'[class.mat-slider-sliding]': '_isSliding',
'[class.mat-slider-thumb-label-showing]': 'thumbLabel',
'[class.mat-slider-vertical]': 'vertical',
'[class.mat-slider-min-value]': '_isMinValue',
'[class.mat-slider-hide-last-tick]': 'disabled || _isMinValue && _thumbGap && _invertAxis',
},
templateUrl: 'slider.html',
styleUrls: ['slider.css'],
inputs: ['disabled'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MdSlider extends _MdSliderMixinBase
implements ControlValueAccessor, OnDestroy, CanDisable {
/** Whether the slider is inverted. */
@Input()
get invert() { return this._invert; }
set invert(value: any) {
this._invert = coerceBooleanProperty(value);
}
private _invert = false;
/** The maximum value that the slider can have. */
@Input()
get max() { return this._max; }
set max(v: number) {
this._max = coerceNumberProperty(v, this._max);
this._percent = this._calculatePercentage(this._value);
// Since this also modifies the percentage, we need to let the change detection know.
this._changeDetectorRef.markForCheck();
}
private _max: number = 100;
/** The minimum value that the slider can have. */
@Input()
get min() { return this._min; }
set min(v: number) {
this._min = coerceNumberProperty(v, this._min);
// If the value wasn't explicitly set by the user, set it to the min.
if (this._value === null) {
this.value = this._min;
}
this._percent = this._calculatePercentage(this._value);
// Since this also modifies the percentage, we need to let the change detection know.
this._changeDetectorRef.markForCheck();
}
private _min: number = 0;
/** The values at which the thumb will snap. */
@Input()
get step() { return this._step; }
set step(v) {
this._step = coerceNumberProperty(v, this._step);
if (this._step % 1 !== 0) {
this._roundLabelTo = this._step.toString().split('.').pop()!.length;
}
// Since this could modify the label, we need to notify the change detection.
this._changeDetectorRef.markForCheck();
}
private _step: number = 1;
/** Whether or not to show the thumb label. */
@Input()
get thumbLabel(): boolean { return this._thumbLabel; }
set thumbLabel(value) { this._thumbLabel = coerceBooleanProperty(value); }
private _thumbLabel: boolean = false;
/** @deprecated */
@Input('thumb-label')
get _thumbLabelDeprecated(): boolean { return this._thumbLabel; }
set _thumbLabelDeprecated(value) { this._thumbLabel = value; }
/**
* How often to show ticks. Relative to the step so that a tick always appears on a step.
* Ex: Tick interval of 4 with a step of 3 will draw a tick every 4 steps (every 12 values).
*/
@Input()
get tickInterval() { return this._tickInterval; }
set tickInterval(value) {
if (value === 'auto') {
this._tickInterval = 'auto';
} else if (typeof value === 'number' || typeof value === 'string') {
this._tickInterval = coerceNumberProperty(value, this._tickInterval as number);
} else {
this._tickInterval = 0;
}
}
private _tickInterval: 'auto' | number = 0;
/** @deprecated */
@Input('tick-interval')
get _tickIntervalDeprecated() { return this.tickInterval; }
set _tickIntervalDeprecated(v) { this.tickInterval = v; }
/** Value of the slider. */
@Input()
get value() {
// If the value needs to be read and it is still uninitialized, initialize it to the min.
if (this._value === null) {
this.value = this._min;
}
return this._value;
}
set value(v: number | null) {
if (v !== this._value) {
this._value = coerceNumberProperty(v, this._value || 0);
this._percent = this._calculatePercentage(this._value);
// Since this also modifies the percentage, we need to let the change detection know.
this._changeDetectorRef.markForCheck();
}
}
private _value: number | null = null;
/** Whether the slider is vertical. */
@Input()
get vertical() { return this._vertical; }
set vertical(value: any) {
this._vertical = coerceBooleanProperty(value);
}
private _vertical = false;
@Input() color: 'primary' | 'accent' | 'warn' = 'accent';
/** Event emitted when the slider value has changed. */
@Output() change = new EventEmitter<MdSliderChange>();
/** Event emitted when the slider thumb moves. */
@Output() input = new EventEmitter<MdSliderChange>();
/** The value to be used for display purposes. */
get displayValue(): string | number {
// Note that this could be improved further by rounding something like 0.999 to 1 or
// 0.899 to 0.9, however it is very performance sensitive, because it gets called on
// every change detection cycle.
if (this._roundLabelTo && this.value && this.value % 1 !== 0) {
return this.value.toFixed(this._roundLabelTo);
}
return this.value || 0;
}
/** onTouch function registered via registerOnTouch (ControlValueAccessor). */
onTouched: () => any = () => {};
/** The percentage of the slider that coincides with the value. */
get percent() { return this._clamp(this._percent); }
private _percent: number = 0;
/**
* Whether or not the thumb is sliding.
* Used to determine if there should be a transition for the thumb and fill track.
*/
_isSliding: boolean = false;
/**
* Whether or not the slider is active (clicked or sliding).
* Used to shrink and grow the thumb as according to the Material Design spec.
*/
_isActive: boolean = false;
/**
* Whether the axis of the slider is inverted.
* (i.e. whether moving the thumb in the positive x or y direction decreases the slider's value).
*/
get _invertAxis() {
// Standard non-inverted mode for a vertical slider should be dragging the thumb from bottom to
// top. However from a y-axis standpoint this is inverted.
return this.vertical ? !this.invert : this.invert;
}
/** Whether the slider is at its minimum value. */
get _isMinValue() {
return this.percent === 0;
}
/**
* The amount of space to leave between the slider thumb and the track fill & track background
* elements.
*/
get _thumbGap() {
if (this.disabled) {
return DISABLED_THUMB_GAP;
}
if (this._isMinValue && !this.thumbLabel) {
return this._isActive ? MIN_VALUE_ACTIVE_THUMB_GAP : MIN_VALUE_NONACTIVE_THUMB_GAP;
}
return 0;
}
/** CSS styles for the track background element. */
get _trackBackgroundStyles(): { [key: string]: string } {
let axis = this.vertical ? 'Y' : 'X';
let sign = this._invertMouseCoords ? '-' : '';
return {
'transform': `translate${axis}(${sign}${this._thumbGap}px) scale${axis}(${1 - this.percent})`
};
}
/** CSS styles for the track fill element. */
get _trackFillStyles(): { [key: string]: string } {
let axis = this.vertical ? 'Y' : 'X';
let sign = this._invertMouseCoords ? '' : '-';
return {
'transform': `translate${axis}(${sign}${this._thumbGap}px) scale${axis}(${this.percent})`
};
}
/** CSS styles for the ticks container element. */
get _ticksContainerStyles(): { [key: string]: string } {
let axis = this.vertical ? 'Y' : 'X';
// For a horizontal slider in RTL languages we push the ticks container off the left edge
// instead of the right edge to avoid causing a horizontal scrollbar to appear.
let sign = !this.vertical && this._direction == 'rtl' ? '' : '-';
let offset = this._tickIntervalPercent / 2 * 100;
return {
'transform': `translate${axis}(${sign}${offset}%)`
};
}
/** CSS styles for the ticks element. */
get _ticksStyles(): { [key: string]: string } {
let tickSize = this._tickIntervalPercent * 100;
let backgroundSize = this.vertical ? `2px ${tickSize}%` : `${tickSize}% 2px`;
let axis = this.vertical ? 'Y' : 'X';
// Depending on the direction we pushed the ticks container, push the ticks the opposite
// direction to re-center them but clip off the end edge. In RTL languages we need to flip the
// ticks 180 degrees so we're really cutting off the end edge abd not the start.
let sign = !this.vertical && this._direction == 'rtl' ? '-' : '';
let rotate = !this.vertical && this._direction == 'rtl' ? ' rotate(180deg)' : '';
let styles: { [key: string]: string } = {
'backgroundSize': backgroundSize,
// Without translateZ ticks sometimes jitter as the slider moves on Chrome & Firefox.
'transform': `translateZ(0) translate${axis}(${sign}${tickSize / 2}%)${rotate}`
};
if (this._isMinValue && this._thumbGap) {
let side = this.vertical ?
(this._invertAxis ? 'Bottom' : 'Top') :
(this._invertAxis ? 'Right' : 'Left');
styles[`padding${side}`] = `${this._thumbGap}px`;
}
return styles;
}
get _thumbContainerStyles(): { [key: string]: string } {
let axis = this.vertical ? 'Y' : 'X';
// For a horizontal slider in RTL languages we push the thumb container off the left edge
// instead of the right edge to avoid causing a horizontal scrollbar to appear.
let invertOffset =
(this._direction == 'rtl' && !this.vertical) ? !this._invertAxis : this._invertAxis;
let offset = (invertOffset ? this.percent : 1 - this.percent) * 100;
return {
'transform': `translate${axis}(-${offset}%)`
};
}
/** The size of a tick interval as a percentage of the size of the track. */
private _tickIntervalPercent: number = 0;
/** A renderer to handle updating the slider's thumb and fill track. */
private _renderer: SliderRenderer;
/** The dimensions of the slider. */
private _sliderDimensions: ClientRect | null = null;
private _controlValueAccessorChangeFn: (value: any) => void = () => {};
/** The last value for which a change event was emitted. */
private _lastChangeValue: number | null;
/** The last value for which an input event was emitted. */
private _lastInputValue: number | null;
/** Decimal places to round to, based on the step amount. */
private _roundLabelTo: number;
/**
* Whether mouse events should be converted to a slider position by calculating their distance
* from the right or bottom edge of the slider as opposed to the top or left.
*/
private get _invertMouseCoords() {
return (this._direction == 'rtl' && !this.vertical) ? !this._invertAxis : this._invertAxis;
}
/** The language direction for this slider element. */
private get _direction() {
return (this._dir && this._dir.value == 'rtl') ? 'rtl' : 'ltr';
}
constructor(renderer: Renderer2, private _elementRef: ElementRef,
private _focusOriginMonitor: FocusOriginMonitor,
private _changeDetectorRef: ChangeDetectorRef,
@Optional() private _dir: Directionality) {
super();
this._focusOriginMonitor
.monitor(this._elementRef.nativeElement, renderer, true)
.subscribe((origin: FocusOrigin) => this._isActive = !!origin && origin !== 'keyboard');
this._renderer = new SliderRenderer(this._elementRef);
}
ngOnDestroy() {
this._focusOriginMonitor.stopMonitoring(this._elementRef.nativeElement);
}
_onMouseenter() {
if (this.disabled) {
return;
}
// We save the dimensions of the slider here so we can use them to update the spacing of the
// ticks and determine where on the slider click and slide events happen.
this._sliderDimensions = this._renderer.getSliderDimensions();
this._updateTickIntervalPercent();
}
_onClick(event: MouseEvent) {
if (this.disabled) {
return;
}
this._isSliding = false;
this._renderer.addFocus();
this._updateValueFromPosition({x: event.clientX, y: event.clientY});
/* Emits a change and input event if the value changed. */
this._emitInputEvent();
this._emitValueIfChanged();
}
_onSlide(event: HammerInput) {
if (this.disabled) {
return;
}
// The slide start event sometimes fails to fire on iOS, so if we're not already in the sliding
// state, call the slide start handler manually.
if (!this._isSliding) {
this._onSlideStart(null);
}
// Prevent the slide from selecting anything else.
event.preventDefault();
this._updateValueFromPosition({x: event.center.x, y: event.center.y});
// Native range elements always emit `input` events when the value changed while sliding.
this._emitInputEvent();
}
_onSlideStart(event: HammerInput | null) {
if (this.disabled) {
return;
}
// Simulate mouseenter in case this is a mobile device.
this._onMouseenter();
this._isSliding = true;
this._renderer.addFocus();
if (event) {
this._updateValueFromPosition({x: event.center.x, y: event.center.y});
event.preventDefault();
}
}
_onSlideEnd() {
this._isSliding = false;
this._emitValueIfChanged();
}
_onFocus() {
// We save the dimensions of the slider here so we can use them to update the spacing of the
// ticks and determine where on the slider click and slide events happen.
this._sliderDimensions = this._renderer.getSliderDimensions();
this._updateTickIntervalPercent();
}
_onBlur() {
this.onTouched();
}
_onKeydown(event: KeyboardEvent) {
if (this.disabled) { return; }
switch (event.keyCode) {
case PAGE_UP:
this._increment(10);
break;
case PAGE_DOWN:
this._increment(-10);
break;
case END:
this.value = this.max;
break;
case HOME:
this.value = this.min;
break;
case LEFT_ARROW:
// NOTE: For a sighted user it would make more sense that when they press an arrow key on an
// inverted slider the thumb moves in that direction. However for a blind user, nothing
// about the slider indicates that it is inverted. They will expect left to be decrement,
// regardless of how it appears on the screen. For speakers ofRTL languages, they probably
// expect left to mean increment. Therefore we flip the meaning of the side arrow keys for
// RTL. For inverted sliders we prefer a good a11y experience to having it "look right" for
// sighted users, therefore we do not swap the meaning.
this._increment(this._direction == 'rtl' ? 1 : -1);
break;
case UP_ARROW:
this._increment(1);
break;
case RIGHT_ARROW:
// See comment on LEFT_ARROW about the conditions under which we flip the meaning.
this._increment(this._direction == 'rtl' ? -1 : 1);
break;
case DOWN_ARROW:
this._increment(-1);
break;
default:
// Return if the key is not one that we explicitly handle to avoid calling preventDefault on
// it.
return;
}
this._emitInputEvent();
this._emitValueIfChanged();
this._isSliding = true;
event.preventDefault();
}
_onKeyup() {
this._isSliding = false;
}
/** Increments the slider by the given number of steps (negative number decrements). */
private _increment(numSteps: number) {
this.value = this._clamp((this.value || 0) + this.step * numSteps, this.min, this.max);
}
/** Calculate the new value from the new physical location. The value will always be snapped. */
private _updateValueFromPosition(pos: {x: number, y: number}) {
if (!this._sliderDimensions) {
return;
}
let offset = this.vertical ? this._sliderDimensions.top : this._sliderDimensions.left;
let size = this.vertical ? this._sliderDimensions.height : this._sliderDimensions.width;
let posComponent = this.vertical ? pos.y : pos.x;
// The exact value is calculated from the event and used to find the closest snap value.
let percent = this._clamp((posComponent - offset) / size);
if (this._invertMouseCoords) {
percent = 1 - percent;
}
let exactValue = this._calculateValue(percent);
// This calculation finds the closest step by finding the closest whole number divisible by the
// step relative to the min.
let closestValue = Math.round((exactValue - this.min) / this.step) * this.step + this.min;
// The value needs to snap to the min and max.
this.value = this._clamp(closestValue, this.min, this.max);
}
/** Emits a change event if the current value is different from the last emitted value. */
private _emitValueIfChanged() {
if (this.value != this._lastChangeValue) {
let event = this._createChangeEvent();
this._lastChangeValue = this.value;
this._controlValueAccessorChangeFn(this.value);
this.change.emit(event);
}
}
/** Emits an input event when the current value is different from the last emitted value. */
private _emitInputEvent() {
if (this.value != this._lastInputValue) {
let event = this._createChangeEvent();
this._lastInputValue = this.value;
this.input.emit(event);
}
}
/** Updates the amount of space between ticks as a percentage of the width of the slider. */
private _updateTickIntervalPercent() {
if (!this.tickInterval || !this._sliderDimensions) {
return;
}
if (this.tickInterval == 'auto') {
let trackSize = this.vertical ? this._sliderDimensions.height : this._sliderDimensions.width;
let pixelsPerStep = trackSize * this.step / (this.max - this.min);
let stepsPerTick = Math.ceil(MIN_AUTO_TICK_SEPARATION / pixelsPerStep);
let pixelsPerTick = stepsPerTick * this.step;
this._tickIntervalPercent = pixelsPerTick / trackSize;
} else {
this._tickIntervalPercent = this.tickInterval * this.step / (this.max - this.min);
}
}
/** Creates a slider change object from the specified value. */
private _createChangeEvent(value = this.value): MdSliderChange {
let event = new MdSliderChange();
event.source = this;
event.value = value;
return event;
}
/** Calculates the percentage of the slider that a value is. */
private _calculatePercentage(value: number | null) {
return ((value || 0) - this.min) / (this.max - this.min);
}
/** Calculates the value a percentage of the slider corresponds to. */
private _calculateValue(percentage: number) {
return this.min + percentage * (this.max - this.min);
}
/** Return a number between two numbers. */
private _clamp(value: number, min = 0, max = 1) {
return Math.max(min, Math.min(value, max));
}
/**
* Sets the model value. Implemented as part of ControlValueAccessor.
* @param value
*/
writeValue(value: any) {
this.value = value;
}
/**
* Registers a callback to eb triggered when the value has changed.
* Implemented as part of ControlValueAccessor.
* @param fn Callback to be registered.
*/
registerOnChange(fn: (value: any) => void) {
this._controlValueAccessorChangeFn = fn;
}
/**
* Registers a callback to be triggered when the component is touched.
* Implemented as part of ControlValueAccessor.
* @param fn Callback to be registered.
*/
registerOnTouched(fn: any) {
this.onTouched = fn;
}
/**
* Sets whether the component should be disabled.
* Implemented as part of ControlValueAccessor.
* @param isDisabled
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
}
}
/**
* Renderer class in order to keep all dom manipulation in one place and outside of the main class.
* @docs-private
*/
export class SliderRenderer {
private _sliderElement: HTMLElement;
constructor(elementRef: ElementRef) {
this._sliderElement = elementRef.nativeElement;
}
/**
* Get the bounding client rect of the slider track element.
* The track is used rather than the native element to ignore the extra space that the thumb can
* take up.
*/
getSliderDimensions() {
let wrapperElement = this._sliderElement.querySelector('.mat-slider-wrapper');
return wrapperElement ? wrapperElement.getBoundingClientRect() : null;
}
/**
* Focuses the native element.
* Currently only used to allow a blur event to fire but will be used with keyboard input later.
*/
addFocus() {
this._sliderElement.focus();
}
}