Skip to content

Commit 25193ca

Browse files
authored
feat(material-experimental/mdc-slider): add skeleton code for MatSliderThumb (#21655)
* created slider-thumb.ts * created MatSliderThumb directive for the mdc-slider input
1 parent 1d168e2 commit 25193ca

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

src/material-experimental/mdc-slider/module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import {CommonModule} from '@angular/common';
1010
import {NgModule} from '@angular/core';
1111
import {MatCommonModule} from '@angular/material-experimental/mdc-core';
1212
import {MatSlider} from './slider';
13+
import {MatSliderThumb} from './slider-thumb';
1314

1415
@NgModule({
1516
imports: [MatCommonModule, CommonModule],
1617
exports: [MatSlider],
17-
declarations: [MatSlider],
18+
declarations: [
19+
MatSlider,
20+
MatSliderThumb,
21+
],
1822
})
1923
export class MatSliderModule {
2024
}

src/material-experimental/mdc-slider/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88

99
export {MatSlider} from './slider';
10+
export {MatSliderThumb} from './slider-thumb';
1011
export {MatSliderModule} from './module';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)