Skip to content

Commit 0558d5b

Browse files
committed
fix(material-experimental/mdc-slider): use thumbPosition instead of thumb
1 parent 3099b97 commit 0558d5b

File tree

1 file changed

+69
-67
lines changed
  • src/material-experimental/mdc-slider

1 file changed

+69
-67
lines changed

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

Lines changed: 69 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MatSliderThumb implements AfterViewInit {
8888
// If the foundation has already been initialized, we need to
8989
// relay any value updates to it so that it can update the UI.
9090
if (this._slider._initialized) {
91-
this._slider._setValue(value, this._thumb);
91+
this._slider._setValue(value, this._thumbPosition);
9292
} else {
9393
// Setup for the MDC foundation.
9494
this._elementRef.nativeElement.setAttribute('value', `${value}`);
@@ -110,7 +110,7 @@ export class MatSliderThumb implements AfterViewInit {
110110
@Output() readonly _focus: EventEmitter<void> = new EventEmitter<void>();
111111

112112
/** Indicates which slider thumb this input corresponds to. */
113-
private _thumb: Thumb = this._elementRef.nativeElement.hasAttribute('matSliderStartThumb')
113+
private _thumbPosition: Thumb = this._elementRef.nativeElement.hasAttribute('matSliderStartThumb')
114114
? Thumb.START
115115
: Thumb.END;
116116

@@ -351,8 +351,8 @@ export class MatSlider implements AfterViewInit, OnDestroy {
351351
}
352352

353353
/** Sets the value of a slider thumb. */
354-
_setValue(value: number, thumb: Thumb): void {
355-
thumb === Thumb.START
354+
_setValue(value: number, thumbPosition: Thumb): void {
355+
thumbPosition === Thumb.START
356356
? this._foundation.setValueStart(value)
357357
: this._foundation.setValue(value);
358358
}
@@ -362,41 +362,43 @@ export class MatSlider implements AfterViewInit, OnDestroy {
362362
return this._inputs.length === 2;
363363
}
364364

365-
/** Gets the slider thumb input of the given thumb. */
366-
_getInput(thumb: Thumb): MatSliderThumb {
367-
return thumb === Thumb.END ? this._inputs.last! : this._inputs.first!;
365+
/** Gets the slider thumb input of the given thumb position. */
366+
_getInput(thumbPosition: Thumb): MatSliderThumb {
367+
return thumbPosition === Thumb.END ? this._inputs.last! : this._inputs.first!;
368368
}
369369

370-
/** Gets the slider thumb HTML input element of the given thumb. */
371-
_getInputElement(thumb: Thumb): HTMLInputElement {
372-
return this._getInput(thumb)._elementRef.nativeElement;
370+
/** Gets the slider thumb HTML input element of the given thumb position. */
371+
_getInputElement(thumbPosition: Thumb): HTMLInputElement {
372+
return this._getInput(thumbPosition)._elementRef.nativeElement;
373373
}
374374

375-
/** Gets the slider thumb HTML element of the given thumb. */
376-
_getThumbElement(thumb: Thumb): HTMLElement {
377-
const thumbElementRef = thumb === Thumb.END ? this._thumbs.last : this._thumbs.first;
375+
/** Gets the slider thumb HTML element of the given thumb position. */
376+
_getThumbElement(thumbPosition: Thumb): HTMLElement {
377+
const thumbElementRef = thumbPosition === Thumb.END ? this._thumbs.last : this._thumbs.first;
378378
return thumbElementRef.nativeElement;
379379
}
380380

381-
/** Gets the slider knob HTML element of the given thumb. */
382-
_getKnobElement(thumb: Thumb): HTMLElement {
383-
const knobElementRef = thumb === Thumb.END ? this._knobs.last : this._knobs.first;
381+
/** Gets the slider knob HTML element of the given thumb position. */
382+
_getKnobElement(thumbPosition: Thumb): HTMLElement {
383+
const knobElementRef = thumbPosition === Thumb.END ? this._knobs.last : this._knobs.first;
384384
return knobElementRef.nativeElement;
385385
}
386386

387-
_getValueIndicatorText(thumb: Thumb) {
388-
return thumb === Thumb.START ? this._startValueIndicatorText : this._endValueIndicatorText;
387+
_getValueIndicatorText(thumbPosition: Thumb) {
388+
return thumbPosition === Thumb.START
389+
? this._startValueIndicatorText
390+
: this._endValueIndicatorText;
389391
}
390392

391393
/**
392-
* Sets the value indicator text of the given thumb using the given value.
394+
* Sets the value indicator text of the given thumb position using the given value.
393395
*
394396
* Uses the `displayWith` function if one has been provided. Otherwise, it just uses the
395397
* numeric value as a string.
396398
*/
397-
_setValueIndicatorText(value: number, thumb: Thumb) {
399+
_setValueIndicatorText(value: number, thumbPosition: Thumb) {
398400
const valueText = this.displayWith ? this.displayWith(value) : `${value}`;
399-
thumb === Thumb.START
401+
thumbPosition === Thumb.START
400402
? this._startValueIndicatorText = valueText
401403
: this._endValueIndicatorText = valueText;
402404
}
@@ -441,40 +443,40 @@ class SliderAdapter implements MDCSliderAdapter {
441443
getAttribute = (attribute: string): string | null => {
442444
return this._delegate._elementRef.nativeElement.getAttribute(attribute);
443445
}
444-
addThumbClass = (className: string, thumb: Thumb): void => {
445-
this._delegate._getThumbElement(thumb).classList.add(className);
446+
addThumbClass = (className: string, thumbPosition: Thumb): void => {
447+
this._delegate._getThumbElement(thumbPosition).classList.add(className);
446448
}
447-
removeThumbClass = (className: string, thumb: Thumb): void => {
448-
this._delegate._getThumbElement(thumb).classList.remove(className);
449+
removeThumbClass = (className: string, thumbPosition: Thumb): void => {
450+
this._delegate._getThumbElement(thumbPosition).classList.remove(className);
449451
}
450-
getInputValue = (thumb: Thumb): string => {
451-
return this._delegate._getInputElement(thumb).value;
452+
getInputValue = (thumbPosition: Thumb): string => {
453+
return this._delegate._getInputElement(thumbPosition).value;
452454
}
453-
setInputValue = (value: string, thumb: Thumb): void => {
454-
this._delegate._getInputElement(thumb).value = value;
455+
setInputValue = (value: string, thumbPosition: Thumb): void => {
456+
this._delegate._getInputElement(thumbPosition).value = value;
455457
}
456-
getInputAttribute = (attribute: string, thumb: Thumb): string | null => {
457-
return this._delegate._getInputElement(thumb).getAttribute(attribute);
458+
getInputAttribute = (attribute: string, thumbPosition: Thumb): string | null => {
459+
return this._delegate._getInputElement(thumbPosition).getAttribute(attribute);
458460
}
459-
setInputAttribute = (attribute: string, value: string, thumb: Thumb): void => {
460-
this._delegate._getInputElement(thumb).setAttribute(attribute, value);
461+
setInputAttribute = (attribute: string, value: string, thumbPosition: Thumb): void => {
462+
this._delegate._getInputElement(thumbPosition).setAttribute(attribute, value);
461463
}
462-
removeInputAttribute = (attribute: string, thumb: Thumb): void => {
463-
this._delegate._getInputElement(thumb).removeAttribute(attribute);
464+
removeInputAttribute = (attribute: string, thumbPosition: Thumb): void => {
465+
this._delegate._getInputElement(thumbPosition).removeAttribute(attribute);
464466
}
465-
focusInput = (thumb: Thumb): void => {
466-
this._delegate._getInputElement(thumb).focus();
467+
focusInput = (thumbPosition: Thumb): void => {
468+
this._delegate._getInputElement(thumbPosition).focus();
467469
}
468-
isInputFocused = (thumb: Thumb): boolean => {
469-
return this._delegate._getInput(thumb)._isFocused();
470+
isInputFocused = (thumbPosition: Thumb): boolean => {
471+
return this._delegate._getInput(thumbPosition)._isFocused();
470472
}
471-
getThumbKnobWidth = (thumb: Thumb): number => {
473+
getThumbKnobWidth = (thumbPosition: Thumb): number => {
472474
// TODO(wagnermaciel): Check if this causes issues for SSR
473475
// once the mdc-slider is added back to the kitchen sink SSR app.
474-
return this._delegate._getKnobElement(thumb).getBoundingClientRect().width;
476+
return this._delegate._getKnobElement(thumbPosition).getBoundingClientRect().width;
475477
}
476-
getThumbBoundingClientRect = (thumb: Thumb): ClientRect => {
477-
return this._delegate._getThumbElement(thumb).getBoundingClientRect();
478+
getThumbBoundingClientRect = (thumbPosition: Thumb): ClientRect => {
479+
return this._delegate._getThumbElement(thumbPosition).getBoundingClientRect();
478480
}
479481
getBoundingClientRect = (): ClientRect => {
480482
return this._delegate._elementRef.nativeElement.getBoundingClientRect();
@@ -483,20 +485,20 @@ class SliderAdapter implements MDCSliderAdapter {
483485
// TODO(wagnermaciel): Actually implementing this.
484486
return false;
485487
}
486-
setThumbStyleProperty = (propertyName: string, value: string, thumb: Thumb): void => {
487-
this._delegate._getThumbElement(thumb).style.setProperty(propertyName, value);
488+
setThumbStyleProperty = (propertyName: string, value: string, thumbPosition: Thumb): void => {
489+
this._delegate._getThumbElement(thumbPosition).style.setProperty(propertyName, value);
488490
}
489-
removeThumbStyleProperty = (propertyName: string, thumb: Thumb): void => {
490-
this._delegate._getThumbElement(thumb).style.removeProperty(propertyName);
491+
removeThumbStyleProperty = (propertyName: string, thumbPosition: Thumb): void => {
492+
this._delegate._getThumbElement(thumbPosition).style.removeProperty(propertyName);
491493
}
492494
setTrackActiveStyleProperty = (propertyName: string, value: string): void => {
493495
this._delegate._trackActive.nativeElement.style.setProperty(propertyName, value);
494496
}
495497
removeTrackActiveStyleProperty = (propertyName: string): void => {
496498
this._delegate._trackActive.nativeElement.style.removeProperty(propertyName);
497499
}
498-
setValueIndicatorText = (value: number, thumb: Thumb): void => {
499-
this._delegate._setValueIndicatorText(value, thumb);
500+
setValueIndicatorText = (value: number, thumbPosition: Thumb): void => {
501+
this._delegate._setValueIndicatorText(value, thumbPosition);
500502
}
501503
getValueToAriaValueTextFn = (): ((value: number) => string) | null => {
502504
return this._delegate.displayWith;
@@ -510,14 +512,14 @@ class SliderAdapter implements MDCSliderAdapter {
510512
}
511513
// We ignore emitChangeEvent and emitInputEvent because the slider inputs
512514
// are already exposed so users can just listen for those events directly themselves.
513-
emitChangeEvent = (value: number, thumb: Thumb): void => {};
514-
emitInputEvent = (value: number, thumb: Thumb): void => {};
515-
emitDragStartEvent = (value: number, thumb: Thumb): void => {
516-
const input = this._delegate._getInput(thumb);
515+
emitChangeEvent = (value: number, thumbPosition: Thumb): void => {};
516+
emitInputEvent = (value: number, thumbPosition: Thumb): void => {};
517+
emitDragStartEvent = (value: number, thumbPosition: Thumb): void => {
518+
const input = this._delegate._getInput(thumbPosition);
517519
input.dragStart.emit({ source: input, parent: this._delegate, value });
518520
}
519-
emitDragEndEvent = (value: number, thumb: Thumb): void => {
520-
const input = this._delegate._getInput(thumb);
521+
emitDragEndEvent = (value: number, thumbPosition: Thumb): void => {
522+
const input = this._delegate._getInput(thumbPosition);
521523
input.dragEnd.emit({ source: input, parent: this._delegate, value });
522524
}
523525
registerEventHandler =
@@ -528,21 +530,21 @@ class SliderAdapter implements MDCSliderAdapter {
528530
<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => {
529531
this._delegate._elementRef.nativeElement.removeEventListener(evtType, handler);
530532
}
531-
registerThumbEventHandler =
532-
<K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
533-
this._delegate._getThumbElement(thumb).addEventListener(evtType, handler);
533+
registerThumbEventHandler = <K extends EventType>
534+
(thumbPosition: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
535+
this._delegate._getThumbElement(thumbPosition).addEventListener(evtType, handler);
534536
}
535-
deregisterThumbEventHandler =
536-
<K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
537-
this._delegate._getThumbElement(thumb).removeEventListener(evtType, handler);
537+
deregisterThumbEventHandler = <K extends EventType>
538+
(thumbPosition: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
539+
this._delegate._getThumbElement(thumbPosition).removeEventListener(evtType, handler);
538540
}
539-
registerInputEventHandler =
540-
<K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
541-
this._delegate._getInputElement(thumb).addEventListener(evtType, handler);
541+
registerInputEventHandler = <K extends EventType>
542+
(thumbPosition: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
543+
this._delegate._getInputElement(thumbPosition).addEventListener(evtType, handler);
542544
}
543-
deregisterInputEventHandler =
544-
<K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
545-
this._delegate._getInputElement(thumb).removeEventListener(evtType, handler);
545+
deregisterInputEventHandler = <K extends EventType>
546+
(thumbPosition: Thumb, evtType: K, handler: SpecificEventListener<K>): void => {
547+
this._delegate._getInputElement(thumbPosition).removeEventListener(evtType, handler);
546548
}
547549
registerBodyEventHandler =
548550
<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => {

0 commit comments

Comments
 (0)