|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import {NumberInput} from '@angular/cdk/coercion'; |
| 10 | +import {DOCUMENT} from '@angular/common'; |
| 11 | +import {Directive, ElementRef, EventEmitter, Inject, Input, Output} from '@angular/core'; |
| 12 | +import {Thumb} from '@material/slider'; |
| 13 | + |
| 14 | +/** |
| 15 | + * The native input used by the MatSlider. |
| 16 | + */ |
| 17 | +@Directive({ |
| 18 | + selector: 'input[mat-slider-thumb]', |
| 19 | + host: { |
| 20 | + 'class': 'mdc-slider__input', |
| 21 | + 'type': 'range', |
| 22 | + '[min]': 'min', |
| 23 | + '[max]': 'max', |
| 24 | + '[step]': 'step', |
| 25 | + '[attr.value]': 'value', |
| 26 | + '(blur)': '_blur.emit()', |
| 27 | + '(focus)': '_focus.emit()', |
| 28 | + } |
| 29 | +}) export class MatSliderThumb { |
| 30 | + /** The current value of this slider input. */ |
| 31 | + @Input() |
| 32 | + get value(): number { return this._value; } |
| 33 | + set value(v: number) { this._value = v; } |
| 34 | + private _value: number; |
| 35 | + |
| 36 | + /** The minimum value that this slider input can have. */ |
| 37 | + @Input() |
| 38 | + get min(): number { return 0; } |
| 39 | + set min(v: number) { throw Error('Invalid attribute "min" on MatSliderThumb.'); } |
| 40 | + |
| 41 | + /** The maximum value that this slider input can have. */ |
| 42 | + @Input() |
| 43 | + get max(): number { return 100; } |
| 44 | + set max(v: number) { throw Error('Invalid attribute "max" on MatSliderThumb.'); } |
| 45 | + |
| 46 | + /** The size of each increment between the values of the slider. */ |
| 47 | + @Input() |
| 48 | + get step(): number { return 1; } |
| 49 | + set step(v: number) { throw Error('Invalid attribute "step" on MatSliderThumb.'); } |
| 50 | + |
| 51 | + /** MDC Slider does not use the disabled attribute it's native inputs. */ |
| 52 | + @Input() |
| 53 | + set disabled(v: boolean) { throw Error('Invalid attribute "disabled" on MatSliderThumb.'); } |
| 54 | + |
| 55 | + /** Event emitted every time the MatSliderThumb is blurred. */ |
| 56 | + @Output() readonly _blur: EventEmitter<void> = new EventEmitter<void>(); |
| 57 | + |
| 58 | + /** Event emitted every time the MatSliderThumb is focused. */ |
| 59 | + @Output() readonly _focus: EventEmitter<void> = new EventEmitter<void>(); |
| 60 | + |
| 61 | + /** Indicates which slider thumb this input corresponds to. */ |
| 62 | + thumb: Thumb; |
| 63 | + |
| 64 | + constructor( |
| 65 | + @Inject(DOCUMENT) private readonly _document: Document, |
| 66 | + private readonly _elementRef: ElementRef<HTMLInputElement>, |
| 67 | + ) {} |
| 68 | + |
| 69 | + /** Returns the hosts native HTML element. */ |
| 70 | + _getHostElement(): HTMLInputElement { |
| 71 | + return this._elementRef.nativeElement; |
| 72 | + } |
| 73 | + |
| 74 | + /** Returns true if this slider input currently has focus. */ |
| 75 | + _isFocused(): boolean { |
| 76 | + return this._document.activeElement === this._getHostElement(); |
| 77 | + } |
| 78 | + |
| 79 | + static ngAcceptInputType_value: NumberInput; |
| 80 | +} |
0 commit comments