Skip to content

Commit 373958d

Browse files
committed
fix(material-experimental/mdc-slider): code review changes
* omitted code in kitchen-sink-mdc.html instead of commenting it out * deleted the MatSliderChange class * renamed MatSliderInteraction to MatSliderThumbInteractionEvent and made it an interface instead of a class * renamed isDisabled to disabled * renamed isDiscrete to discrete * renamed hasTickMarks to showTickMarks * removed spaces from object literals * deleted change and input @outputs * use properties instead of getters for _document, _window, and _hostElement
1 parent 9fd3f2e commit 373958d

File tree

4 files changed

+53
-91
lines changed

4 files changed

+53
-91
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ import {Thumb} from '@material/slider';
6161
/** Indicates which slider thumb this input corresponds to. */
6262
thumb: Thumb;
6363

64+
/** The hosts native HTML element. */
65+
_hostElement: HTMLInputElement;
66+
6467
constructor(
6568
@Inject(DOCUMENT) private readonly _document: Document,
6669
private readonly _elementRef: ElementRef<HTMLInputElement>,
67-
) {}
68-
69-
/** Returns the hosts native HTML element. */
70-
_getHostElement(): HTMLInputElement {
71-
return this._elementRef.nativeElement;
72-
}
70+
) {
71+
this._hostElement = this._elementRef.nativeElement;
72+
}
7373

7474
/** Returns true if this slider input currently has focus. */
7575
_isFocused(): boolean {
76-
return this._document.activeElement === this._getHostElement();
76+
return this._document.activeElement === this._hostElement;
7777
}
7878

7979
static ngAcceptInputType_value: NumberInput;

src/material-experimental/mdc-slider/slider.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="mdc-slider__track--active">
88
<div class="mdc-slider__track--active_fill" #trackActive></div>
99
</div>
10-
<div *ngIf="hasTickMarks" class="mdc-slider__tick-marks" #tickMarkContainer>
10+
<div *ngIf="showTickMarks" class="mdc-slider__tick-marks" #tickMarkContainer>
1111
<div *ngFor="let tickMark of tickMarks" class="{{_getTickMarkClass(tickMark)}}"></div>
1212
</div>
1313
</div>

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

Lines changed: 45 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,13 @@ import {MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
3535
import {SliderAdapter} from './slider-adapter';
3636
import {MatSliderThumb} from './slider-thumb';
3737

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 {
5840
/** The MatSlider that was interacted with. */
5941
source: MatSlider;
6042

6143
/** The thumb that was interacted with. */
6244
thumb: Thumb;
63-
64-
constructor(source: MatSlider, thumb: Thumb) {
65-
this.source = source;
66-
this.thumb = thumb;
67-
}
6845
}
6946

7047
/**
@@ -78,9 +55,9 @@ export class MatSliderInteraction {
7855
host: {
7956
'class': 'mat-mdc-slider mdc-slider',
8057
'[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',
8461
},
8562
exportAs: 'matSlider',
8663
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -97,30 +74,32 @@ export class MatSlider implements AfterViewInit, OnDestroy {
9774
@ViewChild('trackActive') _trackActive: ElementRef<HTMLElement>;
9875

9976
/** The sliders hidden range input(s). */
100-
@ContentChildren(MatSliderThumb, { descendants: false }) _inputs: QueryList<MatSliderThumb>;
77+
@ContentChildren(MatSliderThumb, {descendants: false}) _inputs: QueryList<MatSliderThumb>;
10178

10279
/** Whether the slider is disabled. */
10380
@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);
10784
if (this._initialized) {
10885
this._foundation.setDisabled(v);
10986
}
11087
}
111-
private _isDisabled: boolean = false;
88+
private _disabled: boolean = false;
11289

11390
/** Whether the slider displays a numeric value label upon pressing the thumb. */
11491
@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;
11895

11996
/** Whether the slider displays tick marks along the slider track. */
12097
@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;
124103

125104
/** The minimum value that the slider can have. */
126105
@Input()
@@ -147,19 +126,13 @@ export class MatSlider implements AfterViewInit, OnDestroy {
147126
*/
148127
@Input() displayWith: ((value: number) => string) | null;
149128

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-
156129
/** 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>();
159132

160133
/** 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>();
163136

164137
/** Whether this is a ranged slider. */
165138
get isRange(): boolean { return this._inputs.length === 2; }
@@ -176,6 +149,18 @@ export class MatSlider implements AfterViewInit, OnDestroy {
176149
/** The string representation of the end thumbs value. */
177150
_endValueIndicatorText: string;
178151

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+
179164
/** Used to keep track of & render the active & inactive tick marks on the slider track. */
180165
get tickMarks(): TickMark[] { return this._tickMarks; }
181166
set tickMarks(v: TickMark[]) {
@@ -188,7 +173,11 @@ export class MatSlider implements AfterViewInit, OnDestroy {
188173
private _cdr: ChangeDetectorRef,
189174
private readonly _elementRef: ElementRef<HTMLElement>,
190175
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+
}
192181

193182
ngAfterViewInit() {
194183
this._foundation.init();
@@ -217,32 +206,14 @@ export class MatSlider implements AfterViewInit, OnDestroy {
217206
: this._foundation.setValue(value);
218207
}
219208

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-
238209
/** Gets the slider thumb input of the given thumb. */
239210
_getInput(thumb: Thumb): MatSliderThumb {
240211
return thumb === Thumb.END ? this._inputs.get(this._inputs.length - 1)! : this._inputs.get(0)!;
241212
}
242213

243214
/** Gets the slider thumb HTML input element of the given thumb. */
244215
_getInputElement(thumb: Thumb): HTMLInputElement {
245-
return this._getInput(thumb)._getHostElement();
216+
return this._getInput(thumb)._hostElement;
246217
}
247218

248219
/** Gets the slider thumb HTML element of the given thumb. */
@@ -284,19 +255,14 @@ export class MatSlider implements AfterViewInit, OnDestroy {
284255
return this.isRange ? [Thumb.START, Thumb.END] : [Thumb.END];
285256
}
286257

287-
/** Creates a MatSliderChange event. */
288-
_createChangeEvent(value: number, thumb: Thumb): MatSliderChange {
289-
return new MatSliderChange(this, value, thumb);
290-
}
291-
292258
/** 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};
295261
}
296262

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;
300266
static ngAcceptInputType_min: NumberInput;
301267
static ngAcceptInputType_max: NumberInput;
302268
static ngAcceptInputType_step: NumberInput;

src/universal-app/kitchen-sink-mdc/kitchen-sink-mdc.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ <h2>MDC slide-toggle</h2>
104104
<mat-slide-toggle>with a label</mat-slide-toggle>
105105

106106
<h2>MDC Slider</h2>
107-
<!-- <mat-slider></mat-slider>
108-
<mat-slider value="50"></mat-slider>
109-
<mat-slider tickInterval="1" min="1" max="10" value="5" thumbLabel></mat-slider>
110-
<mat-slider disabled></mat-slider> -->
111107

112108
<h2>MDC Tabs</h2>
113109

0 commit comments

Comments
 (0)