UNPKG

@angular/material

Version:
1,173 lines (1,172 loc) 54.2 kB
import { DOCUMENT, CommonModule } from '@angular/common'; import { forwardRef, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, ElementRef, ChangeDetectorRef, Optional, Attribute, Inject, NgZone, Input, Output, ViewChild, NgModule } from '@angular/core'; import { mixinTabIndex, mixinColor, mixinDisabled, MatCommonModule } from '@angular/material/core'; import { FocusMonitor } from '@angular/cdk/a11y'; import { Directionality } from '@angular/cdk/bidi'; import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion'; import { hasModifierKey, DOWN_ARROW, RIGHT_ARROW, UP_ARROW, LEFT_ARROW, HOME, END, PAGE_DOWN, PAGE_UP } from '@angular/cdk/keycodes'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations'; import { normalizePassiveListenerOptions } from '@angular/cdk/platform'; import { Subscription } from 'rxjs'; /** * @fileoverview added by tsickle * Generated from: src/material/slider/slider.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const activeEventOptions = normalizePassiveListenerOptions({ passive: false }); /** * Visually, a 30px separation between tick marks looks best. This is very subjective but it is * the default separation we chose. * @type {?} */ const MIN_AUTO_TICK_SEPARATION = 30; /** * The thumb gap size for a disabled slider. * @type {?} */ const DISABLED_THUMB_GAP = 7; /** * The thumb gap size for a non-active slider at its minimum value. * @type {?} */ const MIN_VALUE_NONACTIVE_THUMB_GAP = 7; /** * The thumb gap size for an active slider at its minimum value. * @type {?} */ const MIN_VALUE_ACTIVE_THUMB_GAP = 10; /** * Provider Expression that allows mat-slider to register as a ControlValueAccessor. * This allows it to support [(ngModel)] and [formControl]. * \@docs-private * @type {?} */ const MAT_SLIDER_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ () => MatSlider)), multi: true }; /** * A simple change event emitted by the MatSlider component. */ class MatSliderChange { } if (false) { /** * The MatSlider that changed. * @type {?} */ MatSliderChange.prototype.source; /** * The new value of the source slider. * @type {?} */ MatSliderChange.prototype.value; } // Boilerplate for applying mixins to MatSlider. /** * \@docs-private */ class MatSliderBase { /** * @param {?} _elementRef */ constructor(_elementRef) { this._elementRef = _elementRef; } } if (false) { /** @type {?} */ MatSliderBase.prototype._elementRef; } /** @type {?} */ const _MatSliderMixinBase = mixinTabIndex(mixinColor(mixinDisabled(MatSliderBase), 'accent')); /** * 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. */ class MatSlider extends _MatSliderMixinBase { /** * @param {?} elementRef * @param {?} _focusMonitor * @param {?} _changeDetectorRef * @param {?} _dir * @param {?} tabIndex * @param {?=} _animationMode * @param {?=} _ngZone * @param {?=} document */ constructor(elementRef, _focusMonitor, _changeDetectorRef, _dir, tabIndex, _animationMode, _ngZone, /** @breaking-change 11.0.0 make document required */ document) { super(elementRef); this._focusMonitor = _focusMonitor; this._changeDetectorRef = _changeDetectorRef; this._dir = _dir; this._animationMode = _animationMode; this._ngZone = _ngZone; this._invert = false; this._max = 100; this._min = 0; this._step = 1; this._thumbLabel = false; this._tickInterval = 0; this._value = null; this._vertical = false; /** * Event emitted when the slider value has changed. */ this.change = new EventEmitter(); /** * Event emitted when the slider thumb moves. */ this.input = new EventEmitter(); /** * Emits when the raw value of the slider changes. This is here primarily * to facilitate the two-way binding for the `value` input. * \@docs-private */ this.valueChange = new EventEmitter(); /** * onTouch function registered via registerOnTouch (ControlValueAccessor). */ this.onTouched = (/** * @return {?} */ () => { }); this._percent = 0; /** * Whether or not the thumb is sliding. * Used to determine if there should be a transition for the thumb and fill track. */ this._isSliding = 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. */ this._isActive = false; /** * The size of a tick interval as a percentage of the size of the track. */ this._tickIntervalPercent = 0; /** * The dimensions of the slider. */ this._sliderDimensions = null; this._controlValueAccessorChangeFn = (/** * @return {?} */ () => { }); /** * Subscription to the Directionality change EventEmitter. */ this._dirChangeSubscription = Subscription.EMPTY; /** * Called when the user has put their pointer down on the slider. */ this._pointerDown = (/** * @param {?} event * @return {?} */ (event) => { // Don't do anything if the slider is disabled or the // user is using anything other than the main mouse button. if (this.disabled || this._isSliding || (!isTouchEvent(event) && event.button !== 0)) { return; } this._runInsideZone((/** * @return {?} */ () => { /** @type {?} */ const oldValue = this.value; /** @type {?} */ const pointerPosition = getPointerPositionOnPage(event); this._isSliding = true; this._lastPointerEvent = event; event.preventDefault(); this._focusHostElement(); this._onMouseenter(); // Simulate mouseenter in case this is a mobile device. this._bindGlobalEvents(event); this._focusHostElement(); this._updateValueFromPosition(pointerPosition); this._valueOnSlideStart = this.value; this._pointerPositionOnStart = pointerPosition; // Emit a change and input event if the value changed. if (oldValue != this.value) { this._emitInputEvent(); this._emitChangeEvent(); } })); }); /** * Called when the user has moved their pointer after * starting to drag. Bound on the document level. */ this._pointerMove = (/** * @param {?} event * @return {?} */ (event) => { if (this._isSliding) { // Prevent the slide from selecting anything else. event.preventDefault(); /** @type {?} */ const oldValue = this.value; this._lastPointerEvent = event; this._updateValueFromPosition(getPointerPositionOnPage(event)); // Native range elements always emit `input` events when the value changed while sliding. if (oldValue != this.value) { this._emitInputEvent(); } } }); /** * Called when the user has lifted their pointer. Bound on the document level. */ this._pointerUp = (/** * @param {?} event * @return {?} */ (event) => { if (this._isSliding) { /** @type {?} */ const pointerPositionOnStart = this._pointerPositionOnStart; /** @type {?} */ const currentPointerPosition = getPointerPositionOnPage(event); event.preventDefault(); this._removeGlobalEvents(); this._valueOnSlideStart = this._pointerPositionOnStart = this._lastPointerEvent = null; this._isSliding = false; if (this._valueOnSlideStart != this.value && !this.disabled && pointerPositionOnStart && (pointerPositionOnStart.x !== currentPointerPosition.x || pointerPositionOnStart.y !== currentPointerPosition.y)) { this._emitChangeEvent(); } } }); /** * Called when the window has lost focus. */ this._windowBlur = (/** * @return {?} */ () => { // If the window is blurred while dragging we need to stop dragging because the // browser won't dispatch the `mouseup` and `touchend` events anymore. if (this._lastPointerEvent) { this._pointerUp(this._lastPointerEvent); } }); this._document = document; this.tabIndex = parseInt(tabIndex) || 0; this._runOutsizeZone((/** * @return {?} */ () => { /** @type {?} */ const element = elementRef.nativeElement; element.addEventListener('mousedown', this._pointerDown, activeEventOptions); element.addEventListener('touchstart', this._pointerDown, activeEventOptions); })); } /** * Whether the slider is inverted. * @return {?} */ get invert() { return this._invert; } /** * @param {?} value * @return {?} */ set invert(value) { this._invert = coerceBooleanProperty(value); } /** * The maximum value that the slider can have. * @return {?} */ get max() { return this._max; } /** * @param {?} v * @return {?} */ set max(v) { 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(); } /** * The minimum value that the slider can have. * @return {?} */ get min() { return this._min; } /** * @param {?} v * @return {?} */ set min(v) { 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(); } /** * The values at which the thumb will snap. * @return {?} */ get step() { return this._step; } /** * @param {?} v * @return {?} */ set step(v) { this._step = coerceNumberProperty(v, this._step); if (this._step % 1 !== 0) { this._roundToDecimal = (/** @type {?} */ (this._step.toString().split('.').pop())).length; } // Since this could modify the label, we need to notify the change detection. this._changeDetectorRef.markForCheck(); } /** * Whether or not to show the thumb label. * @return {?} */ get thumbLabel() { return this._thumbLabel; } /** * @param {?} value * @return {?} */ set thumbLabel(value) { this._thumbLabel = coerceBooleanProperty(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). * @return {?} */ get tickInterval() { return this._tickInterval; } /** * @param {?} value * @return {?} */ set tickInterval(value) { if (value === 'auto') { this._tickInterval = 'auto'; } else if (typeof value === 'number' || typeof value === 'string') { this._tickInterval = coerceNumberProperty(value, (/** @type {?} */ (this._tickInterval))); } else { this._tickInterval = 0; } } /** * Value of the slider. * @return {?} */ 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; } /** * @param {?} v * @return {?} */ set value(v) { if (v !== this._value) { /** @type {?} */ let value = coerceNumberProperty(v); // While incrementing by a decimal we can end up with values like 33.300000000000004. // Truncate it to ensure that it matches the label and to make it easier to work with. if (this._roundToDecimal) { value = parseFloat(value.toFixed(this._roundToDecimal)); } this._value = value; this._percent = this._calculatePercentage(this._value); // Since this also modifies the percentage, we need to let the change detection know. this._changeDetectorRef.markForCheck(); } } /** * Whether the slider is vertical. * @return {?} */ get vertical() { return this._vertical; } /** * @param {?} value * @return {?} */ set vertical(value) { this._vertical = coerceBooleanProperty(value); } /** * The value to be used for display purposes. * @return {?} */ get displayValue() { if (this.displayWith) { // Value is never null but since setters and getters cannot have // different types, the value getter is also typed to return null. return this.displayWith((/** @type {?} */ (this.value))); } // 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._roundToDecimal && this.value && this.value % 1 !== 0) { return this.value.toFixed(this._roundToDecimal); } return this.value || 0; } /** * set focus to the host element * @param {?=} options * @return {?} */ focus(options) { this._focusHostElement(options); } /** * blur the host element * @return {?} */ blur() { this._blurHostElement(); } /** * The percentage of the slider that coincides with the value. * @return {?} */ get percent() { return this._clamp(this._percent); } /** * 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). * @return {?} */ 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. * @return {?} */ get _isMinValue() { return this.percent === 0; } /** * The amount of space to leave between the slider thumb and the track fill & track background * elements. * @return {?} */ 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. * @return {?} */ get _trackBackgroundStyles() { /** @type {?} */ const axis = this.vertical ? 'Y' : 'X'; /** @type {?} */ const scale = this.vertical ? `1, ${1 - this.percent}, 1` : `${1 - this.percent}, 1, 1`; /** @type {?} */ const sign = this._shouldInvertMouseCoords() ? '-' : ''; return { // scale3d avoids some rendering issues in Chrome. See #12071. transform: `translate${axis}(${sign}${this._thumbGap}px) scale3d(${scale})` }; } /** * CSS styles for the track fill element. * @return {?} */ get _trackFillStyles() { /** @type {?} */ const percent = this.percent; /** @type {?} */ const axis = this.vertical ? 'Y' : 'X'; /** @type {?} */ const scale = this.vertical ? `1, ${percent}, 1` : `${percent}, 1, 1`; /** @type {?} */ const sign = this._shouldInvertMouseCoords() ? '' : '-'; return { // scale3d avoids some rendering issues in Chrome. See #12071. transform: `translate${axis}(${sign}${this._thumbGap}px) scale3d(${scale})`, // iOS Safari has a bug where it won't re-render elements which start of as `scale(0)` until // something forces a style recalculation on it. Since we'll end up with `scale(0)` when // the value of the slider is 0, we can easily get into this situation. We force a // recalculation by changing the element's `display` when it goes from 0 to any other value. display: percent === 0 ? 'none' : '' }; } /** * CSS styles for the ticks container element. * @return {?} */ get _ticksContainerStyles() { /** @type {?} */ 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. /** @type {?} */ let sign = !this.vertical && this._getDirection() == 'rtl' ? '' : '-'; /** @type {?} */ let offset = this._tickIntervalPercent / 2 * 100; return { 'transform': `translate${axis}(${sign}${offset}%)` }; } /** * CSS styles for the ticks element. * @return {?} */ get _ticksStyles() { /** @type {?} */ let tickSize = this._tickIntervalPercent * 100; /** @type {?} */ let backgroundSize = this.vertical ? `2px ${tickSize}%` : `${tickSize}% 2px`; /** @type {?} */ 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. /** @type {?} */ let sign = !this.vertical && this._getDirection() == 'rtl' ? '-' : ''; /** @type {?} */ let rotate = !this.vertical && this._getDirection() == 'rtl' ? ' rotate(180deg)' : ''; /** @type {?} */ let styles = { '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) { /** @type {?} */ let side = this.vertical ? (this._invertAxis ? 'Bottom' : 'Top') : (this._invertAxis ? 'Right' : 'Left'); styles[`padding${side}`] = `${this._thumbGap}px`; } return styles; } /** * @return {?} */ get _thumbContainerStyles() { /** @type {?} */ 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. /** @type {?} */ let invertOffset = (this._getDirection() == 'rtl' && !this.vertical) ? !this._invertAxis : this._invertAxis; /** @type {?} */ let offset = (invertOffset ? this.percent : 1 - this.percent) * 100; return { 'transform': `translate${axis}(-${offset}%)` }; } /** * 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. * @return {?} */ _shouldInvertMouseCoords() { return (this._getDirection() == 'rtl' && !this.vertical) ? !this._invertAxis : this._invertAxis; } /** * The language direction for this slider element. * @private * @return {?} */ _getDirection() { return (this._dir && this._dir.value == 'rtl') ? 'rtl' : 'ltr'; } /** * @return {?} */ ngOnInit() { this._focusMonitor .monitor(this._elementRef, true) .subscribe((/** * @param {?} origin * @return {?} */ (origin) => { this._isActive = !!origin && origin !== 'keyboard'; this._changeDetectorRef.detectChanges(); })); if (this._dir) { this._dirChangeSubscription = this._dir.change.subscribe((/** * @return {?} */ () => { this._changeDetectorRef.markForCheck(); })); } } /** * @return {?} */ ngOnDestroy() { /** @type {?} */ const element = this._elementRef.nativeElement; element.removeEventListener('mousedown', this._pointerDown, activeEventOptions); element.removeEventListener('touchstart', this._pointerDown, activeEventOptions); this._lastPointerEvent = null; this._removeGlobalEvents(); this._focusMonitor.stopMonitoring(this._elementRef); this._dirChangeSubscription.unsubscribe(); } /** * @return {?} */ _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._getSliderDimensions(); this._updateTickIntervalPercent(); } /** * @return {?} */ _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._getSliderDimensions(); this._updateTickIntervalPercent(); } /** * @return {?} */ _onBlur() { this.onTouched(); } /** * @param {?} event * @return {?} */ _onKeydown(event) { if (this.disabled || hasModifierKey(event)) { return; } /** @type {?} */ const oldValue = this.value; 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._getDirection() == '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._getDirection() == '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; } if (oldValue != this.value) { this._emitInputEvent(); this._emitChangeEvent(); } this._isSliding = true; event.preventDefault(); } /** * @return {?} */ _onKeyup() { this._isSliding = false; } /** * Binds our global move and end events. They're bound at the document level and only while * dragging so that the user doesn't have to keep their pointer exactly over the slider * as they're swiping across the screen. * @private * @param {?} triggerEvent * @return {?} */ _bindGlobalEvents(triggerEvent) { if (typeof this._document !== 'undefined' && this._document) { /** @type {?} */ const body = this._document.body; /** @type {?} */ const isTouch = isTouchEvent(triggerEvent); /** @type {?} */ const moveEventName = isTouch ? 'touchmove' : 'mousemove'; /** @type {?} */ const endEventName = isTouch ? 'touchend' : 'mouseup'; body.addEventListener(moveEventName, this._pointerMove, activeEventOptions); body.addEventListener(endEventName, this._pointerUp, activeEventOptions); if (isTouch) { body.addEventListener('touchcancel', this._pointerUp, activeEventOptions); } } if (typeof window !== 'undefined' && window) { window.addEventListener('blur', this._windowBlur); } } /** * Removes any global event listeners that we may have added. * @private * @return {?} */ _removeGlobalEvents() { if (typeof this._document !== 'undefined' && this._document) { /** @type {?} */ const body = this._document.body; body.removeEventListener('mousemove', this._pointerMove, activeEventOptions); body.removeEventListener('mouseup', this._pointerUp, activeEventOptions); body.removeEventListener('touchmove', this._pointerMove, activeEventOptions); body.removeEventListener('touchend', this._pointerUp, activeEventOptions); body.removeEventListener('touchcancel', this._pointerUp, activeEventOptions); } if (typeof window !== 'undefined' && window) { window.removeEventListener('blur', this._windowBlur); } } /** * Increments the slider by the given number of steps (negative number decrements). * @private * @param {?} numSteps * @return {?} */ _increment(numSteps) { 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 * @param {?} pos * @return {?} */ _updateValueFromPosition(pos) { if (!this._sliderDimensions) { return; } /** @type {?} */ let offset = this.vertical ? this._sliderDimensions.top : this._sliderDimensions.left; /** @type {?} */ let size = this.vertical ? this._sliderDimensions.height : this._sliderDimensions.width; /** @type {?} */ let posComponent = this.vertical ? pos.y : pos.x; // The exact value is calculated from the event and used to find the closest snap value. /** @type {?} */ let percent = this._clamp((posComponent - offset) / size); if (this._shouldInvertMouseCoords()) { percent = 1 - percent; } // Since the steps may not divide cleanly into the max value, if the user // slid to 0 or 100 percent, we jump to the min/max value. This approach // is slightly more intuitive than using `Math.ceil` below, because it // follows the user's pointer closer. if (percent === 0) { this.value = this.min; } else if (percent === 1) { this.value = this.max; } else { /** @type {?} */ const exactValue = this._calculateValue(percent); // This calculation finds the closest step by finding the closest // whole number divisible by the step relative to the min. /** @type {?} */ const 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 * @return {?} */ _emitChangeEvent() { this._controlValueAccessorChangeFn(this.value); this.valueChange.emit(this.value); this.change.emit(this._createChangeEvent()); } /** * Emits an input event when the current value is different from the last emitted value. * @private * @return {?} */ _emitInputEvent() { this.input.emit(this._createChangeEvent()); } /** * Updates the amount of space between ticks as a percentage of the width of the slider. * @private * @return {?} */ _updateTickIntervalPercent() { if (!this.tickInterval || !this._sliderDimensions) { return; } if (this.tickInterval == 'auto') { /** @type {?} */ let trackSize = this.vertical ? this._sliderDimensions.height : this._sliderDimensions.width; /** @type {?} */ let pixelsPerStep = trackSize * this.step / (this.max - this.min); /** @type {?} */ let stepsPerTick = Math.ceil(MIN_AUTO_TICK_SEPARATION / pixelsPerStep); /** @type {?} */ 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 * @param {?=} value * @return {?} */ _createChangeEvent(value = this.value) { /** @type {?} */ let event = new MatSliderChange(); event.source = this; event.value = value; return event; } /** * Calculates the percentage of the slider that a value is. * @private * @param {?} value * @return {?} */ _calculatePercentage(value) { return ((value || 0) - this.min) / (this.max - this.min); } /** * Calculates the value a percentage of the slider corresponds to. * @private * @param {?} percentage * @return {?} */ _calculateValue(percentage) { return this.min + percentage * (this.max - this.min); } /** * Return a number between two numbers. * @private * @param {?} value * @param {?=} min * @param {?=} max * @return {?} */ _clamp(value, min = 0, max = 1) { return Math.max(min, Math.min(value, max)); } /** * 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. * @private * @return {?} */ _getSliderDimensions() { return this._sliderWrapper ? this._sliderWrapper.nativeElement.getBoundingClientRect() : null; } /** * Focuses the native element. * Currently only used to allow a blur event to fire but will be used with keyboard input later. * @private * @param {?=} options * @return {?} */ _focusHostElement(options) { this._elementRef.nativeElement.focus(options); } /** * Blurs the native element. * @private * @return {?} */ _blurHostElement() { this._elementRef.nativeElement.blur(); } /** * Runs a callback inside of the NgZone, if possible. * @private * @param {?} fn * @return {?} */ _runInsideZone(fn) { // @breaking-change 9.0.0 Remove this function once `_ngZone` is a required parameter. this._ngZone ? this._ngZone.run(fn) : fn(); } /** * Runs a callback outside of the NgZone, if possible. * @private * @param {?} fn * @return {?} */ _runOutsizeZone(fn) { // @breaking-change 9.0.0 Remove this function once `_ngZone` is a required parameter. this._ngZone ? this._ngZone.runOutsideAngular(fn) : fn(); } /** * Sets the model value. Implemented as part of ControlValueAccessor. * @param {?} value * @return {?} */ writeValue(value) { this.value = value; } /** * Registers a callback to be triggered when the value has changed. * Implemented as part of ControlValueAccessor. * @param {?} fn Callback to be registered. * @return {?} */ registerOnChange(fn) { 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. * @return {?} */ registerOnTouched(fn) { this.onTouched = fn; } /** * Sets whether the component should be disabled. * Implemented as part of ControlValueAccessor. * @param {?} isDisabled * @return {?} */ setDisabledState(isDisabled) { this.disabled = isDisabled; } } MatSlider.decorators = [ { type: Component, args: [{ selector: 'mat-slider', exportAs: 'matSlider', providers: [MAT_SLIDER_VALUE_ACCESSOR], host: { '(focus)': '_onFocus()', '(blur)': '_onBlur()', '(keydown)': '_onKeydown($event)', '(keyup)': '_onKeyup()', '(mouseenter)': '_onMouseenter()', // On Safari starting to slide temporarily triggers text selection mode which // show the wrong cursor. We prevent it by stopping the `selectstart` event. '(selectstart)': '$event.preventDefault()', 'class': 'mat-slider', 'role': 'slider', '[tabIndex]': 'tabIndex', '[attr.aria-disabled]': 'disabled', '[attr.aria-valuemax]': 'max', '[attr.aria-valuemin]': 'min', '[attr.aria-valuenow]': 'value', '[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"', '[class.mat-slider-disabled]': 'disabled', '[class.mat-slider-has-ticks]': 'tickInterval', '[class.mat-slider-horizontal]': '!vertical', '[class.mat-slider-axis-inverted]': '_invertAxis', // Class binding which is only used by the test harness as there is no other // way for the harness to detect if mouse coordinates need to be inverted. '[class.mat-slider-invert-mouse-coords]': '_shouldInvertMouseCoords()', '[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', '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"', }, template: "<div class=\"mat-slider-wrapper\" #sliderWrapper>\n <div class=\"mat-slider-track-wrapper\">\n <div class=\"mat-slider-track-background\" [ngStyle]=\"_trackBackgroundStyles\"></div>\n <div class=\"mat-slider-track-fill\" [ngStyle]=\"_trackFillStyles\"></div>\n </div>\n <div class=\"mat-slider-ticks-container\" [ngStyle]=\"_ticksContainerStyles\">\n <div class=\"mat-slider-ticks\" [ngStyle]=\"_ticksStyles\"></div>\n </div>\n <div class=\"mat-slider-thumb-container\" [ngStyle]=\"_thumbContainerStyles\">\n <div class=\"mat-slider-focus-ring\"></div>\n <div class=\"mat-slider-thumb\"></div>\n <div class=\"mat-slider-thumb-label\">\n <span class=\"mat-slider-thumb-label-text\">{{displayValue}}</span>\n </div>\n </div>\n</div>\n", inputs: ['disabled', 'color', 'tabIndex'], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, styles: [".mat-slider{display:inline-block;position:relative;box-sizing:border-box;padding:8px;outline:none;vertical-align:middle}.mat-slider:not(.mat-slider-disabled):active,.mat-slider.mat-slider-sliding:not(.mat-slider-disabled){cursor:-webkit-grabbing;cursor:grabbing}.mat-slider-wrapper{position:absolute}.mat-slider-track-wrapper{position:absolute;top:0;left:0;overflow:hidden}.mat-slider-track-fill{position:absolute;transform-origin:0 0;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-track-background{position:absolute;transform-origin:100% 100%;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-ticks-container{position:absolute;left:0;top:0;overflow:hidden}.mat-slider-ticks{background-repeat:repeat;background-clip:content-box;box-sizing:border-box;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-thumb-container{position:absolute;z-index:1;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-focus-ring{position:absolute;width:30px;height:30px;border-radius:50%;transform:scale(0);opacity:0;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1),opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider.cdk-keyboard-focused .mat-slider-focus-ring,.mat-slider.cdk-program-focused .mat-slider-focus-ring{transform:scale(1);opacity:1}.mat-slider:not(.mat-slider-disabled):not(.mat-slider-sliding) .mat-slider-thumb-label,.mat-slider:not(.mat-slider-disabled):not(.mat-slider-sliding) .mat-slider-thumb{cursor:-webkit-grab;cursor:grab}.mat-slider-thumb{position:absolute;right:-10px;bottom:-10px;box-sizing:border-box;width:20px;height:20px;border:3px solid transparent;border-radius:50%;transform:scale(0.7);transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1),border-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-thumb-label{display:none;align-items:center;justify-content:center;position:absolute;width:28px;height:28px;border-radius:50%;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),border-radius 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.cdk-high-contrast-active .mat-slider-thumb-label{outline:solid 1px}.mat-slider-thumb-label-text{z-index:1;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-sliding .mat-slider-track-fill,.mat-slider-sliding .mat-slider-track-background,.mat-slider-sliding .mat-slider-thumb-container{transition-duration:0ms}.mat-slider-has-ticks .mat-slider-wrapper::after{content:\"\";position:absolute;border-width:0;border-style:solid;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-has-ticks.cdk-focused:not(.mat-slider-hide-last-tick) .mat-slider-wrapper::after,.mat-slider-has-ticks:hover:not(.mat-slider-hide-last-tick) .mat-slider-wrapper::after{opacity:1}.mat-slider-has-ticks.cdk-focused:not(.mat-slider-disabled) .mat-slider-ticks,.mat-slider-has-ticks:hover:not(.mat-slider-disabled) .mat-slider-ticks{opacity:1}.mat-slider-thumb-label-showing .mat-slider-focus-ring{display:none}.mat-slider-thumb-label-showing .mat-slider-thumb-label{display:flex}.mat-slider-axis-inverted .mat-slider-track-fill{transform-origin:100% 100%}.mat-slider-axis-inverted .mat-slider-track-background{transform-origin:0 0}.mat-slider:not(.mat-slider-disabled).cdk-focused.mat-slider-thumb-label-showing .mat-slider-thumb{transform:scale(0)}.mat-slider:not(.mat-slider-disabled).cdk-focused .mat-slider-thumb-label{border-radius:50% 50% 0}.mat-slider:not(.mat-slider-disabled).cdk-focused .mat-slider-thumb-label-text{opacity:1}.mat-slider:not(.mat-slider-disabled).cdk-mouse-focused .mat-slider-thumb,.mat-slider:not(.mat-slider-disabled).cdk-touch-focused .mat-slider-thumb,.mat-slider:not(.mat-slider-disabled).cdk-program-focused .mat-slider-thumb{border-width:2px;transform:scale(1)}.mat-slider-disabled .mat-slider-focus-ring{transform:scale(0);opacity:0}.mat-slider-disabled .mat-slider-thumb{border-width:4px;transform:scale(0.5)}.mat-slider-disabled .mat-slider-thumb-label{display:none}.mat-slider-horizontal{height:48px;min-width:128px}.mat-slider-horizontal .mat-slider-wrapper{height:2px;top:23px;left:8px;right:8px}.mat-slider-horizontal .mat-slider-wrapper::after{height:2px;border-left-width:2px;right:0;top:0}.mat-slider-horizontal .mat-slider-track-wrapper{height:2px;width:100%}.mat-slider-horizontal .mat-slider-track-fill{height:2px;width:100%;transform:scaleX(0)}.mat-slider-horizontal .mat-slider-track-background{height:2px;width:100%;transform:scaleX(1)}.mat-slider-horizontal .mat-slider-ticks-container{height:2px;width:100%}.cdk-high-contrast-active .mat-slider-horizontal .mat-slider-ticks-container{height:0;outline:solid 2px;top:1px}.mat-slider-horizontal .mat-slider-ticks{height:2px;width:100%}.mat-slider-horizontal .mat-slider-thumb-container{width:100%;height:0;top:50%}.mat-slider-horizontal .mat-slider-focus-ring{top:-15px;right:-15px}.mat-slider-horizontal .mat-slider-thumb-label{right:-14px;top:-40px;transform:translateY(26px) scale(0.01) rotate(45deg)}.mat-slider-horizontal .mat-slider-thumb-label-text{transform:rotate(-45deg)}.mat-slider-horizontal.cdk-focused .mat-slider-thumb-label{transform:rotate(45deg)}.cdk-high-contrast-active .mat-slider-horizontal.cdk-focused .mat-slider-thumb-label,.cdk-high-contrast-active .mat-slider-horizontal.cdk-focused .mat-slider-thumb-label-text{transform:none}.mat-slider-vertical{width:48px;min-height:128px}.mat-slider-vertical .mat-slider-wrapper{width:2px;top:8px;bottom:8px;left:23px}.mat-slider-vertical .mat-slider-wrapper::after{width:2px;border-top-width:2px;bottom:0;left:0}.mat-slider-vertical .mat-slider-track-wrapper{height:100%;width:2px}.mat-slider-vertical .mat-slider-track-fill{height:100%;width:2px;transform:scaleY(0)}.mat-slider-vertical .mat-slider-track-background{height:100%;width:2px;transform:scaleY(1)}.mat-slider-vertical .mat-slider-ticks-container{width:2px;height:100%}.cdk-high-contrast-active .mat-slider-vertical .mat-slider-ticks-container{width:0;outline:solid 2px;left:1px}.mat-slider-vertical .mat-slider-focus-ring{bottom:-15px;left:-15px}.mat-slider-vertical .mat-slider-ticks{width:2px;height:100%}.mat-slider-vertical .mat-slider-thumb-container{height:100%;width:0;left:50%}.mat-slider-vertical .mat-slider-thumb{-webkit-backface-visibility:hidden;backface-visibility:hidden}.mat-slider-vertical .mat-slider-thumb-label{bottom:-14px;left:-40px;transform:translateX(26px) scale(0.01) rotate(-45deg)}.mat-slider-vertical .mat-slider-thumb-label-text{transform:rotate(45deg)}.mat-slider-vertical.cdk-focused .mat-slider-thumb-label{transform:rotate(-45deg)}[dir=rtl] .mat-slider-wrapper::after{left:0;right:auto}[dir=rtl] .mat-slider-horizontal .mat-slider-track-fill{transform-origin:100% 100%}[dir=rtl] .mat-slider-horizontal .mat-slider-track-background{transform-origin:0 0}[dir=rtl] .mat-slider-horizontal.mat-slider-axis-inverted .mat-slider-track-fill{transform-origin:0 0}[dir=rtl] .mat-slider-horizontal.mat-slider-axis-inverted .mat-slider-track-background{transform-origin:100% 100%}.mat-slider._mat-animation-noopable .mat-slider-track-fill,.mat-slider._mat-animation-noopable .mat-slider-track-background,.mat-slider._mat-animation-noopable .mat-slider-ticks,.mat-slider._mat-animation-noopable .mat-slider-thumb-container,.mat-slider._mat-animation-noopable .mat-slider-focus-ring,.mat-slider._mat-animation-noopable .mat-slider-thumb,.mat-slider._mat-animation-noopable .mat-slider-thumb-label,.mat-slider._mat-animation-noopable .mat-slider-thumb-label-text,.mat-slider._mat-animation-noopable .mat-slider-has-ticks .mat-slider-wrapper::after{transition:none}\n"] }] } ]; /** @nocollapse */ MatSlider.ctorParameters = () => [ { type: ElementRef }, { type: FocusMonitor }, { type: ChangeDetectorRef }, { type: Directionality, decorators: [{ type: Optional }] }, { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] }, { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] }, { type: NgZone }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] } ]; MatSlider.propDecorators = { invert: [{ type: Input }], max: [{ type: Input }], min: [{ type: Input }], step: [{ type: Input }], thumbLabel: [{ type: Input }], tickInterval: [{ type: Input }], value: [{ type: Input }], displayWith: [{ type: Input }], vertical: [{ type: Input }], change: [{ type: Output }], input: [{ type: Output }], valueChange: [{ type: Output }], _sliderWrapper: [{ type: ViewChild, args: ['sliderWrapper',] }] }; if (false) { /** @type {?} */ MatSlider.ngAcceptInputType_invert; /** @type {?} */ MatSlider.ngAcceptInputType_max; /** @type {?} */ MatSlider.ngAcceptInputType_min; /** @type {?} */ MatSlider.ngAcceptInputType_step; /** @type {?} */ MatSlider.ngAcceptInputType_thumbLabel; /** @type {?} */ MatSlider.ngAcceptInputType_tickInterval; /** @type {?} */ MatSlider.ngAcceptInputType_value; /** @type {?} */ MatSlider.ngAcceptInputType_vertical; /** @type {?} */ MatSlider.ngAcceptInputType_disabled; /** * @type {?} * @private */ MatSlider.prototype._invert; /** * @type {?} * @private */ MatSlider.prototype._max; /** * @type {?} * @private */ MatSlider.prototype._min; /** * @type {?} * @private */ MatSlider.prototype._step; /** * @type {?} * @private */ MatSlider.prototype._thumbLabel; /** * @type {?} * @private */ MatSlider.prototype._tickInterval; /** * @type {?} * @private */ MatSlider.prototype._value; /** * Function that will be used to format the value before it is displayed * in the thumb label. Can be used to format very large number in order * for them to fit into the slider thumb. * @type {?} */ MatSlider.prototype.displayWith; /** * @type {?} * @private */ MatSlider.prototype._vertical; /** * Event emitted when the slider value has changed. * @type {?} */ MatSlider.prototype.change; /** * Event emitted when the slider thumb moves. * @type {?} */ MatSlider.prototype.input; /** * Emits when the raw value of the slider changes. This is here primarily * to facilitate the two-way binding for the `value` input. * \@docs-private * @type {?} */ MatSlider.prototype.valueChange; /** * onTouch function registered via registerOnTouch (ControlValueAccessor). * @type {?} */ MatSlider.prototype.onTouched; /** * @type {?} * @private */ MatSlider.prototype._percent; /** * Whether or not the thumb is sliding. * Used to determine if there should be a transition for the thumb and fill track. * @type {?} */ MatSlider.prototype._isSliding; /** * Whether or not the slider is active (clicked or sliding). * Used to shrink and grow the thumb as according to the Material Design spec. * @type {?} */ MatSlider.prototype._isActive; /** * The size of a tick interval as a percentage of the size of the track. * @type {?} * @private