Skip to content

Commit ea8b155

Browse files
committed
feat(material-experimental/mdc-slider): add support for disabling ripples
1 parent 0884c0b commit ea8b155

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<mat-slider-visual-thumb
1717
*ngFor="let thumb of _inputs"
1818
[discrete]="discrete"
19+
[disableRipple]="_isRippleDisabled()"
1920
[thumbPosition]="thumb._thumbPosition"
2021
[valueIndicatorText]="_getValueIndicatorText(thumb._thumbPosition)">
2122
</mat-slider-visual-thumb>

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ import {
4040
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
4141
import {
4242
CanColorCtor,
43+
CanDisableRipple,
44+
CanDisableRippleCtor,
4345
MatRipple,
46+
MAT_RIPPLE_GLOBAL_OPTIONS,
4447
mixinColor,
48+
mixinDisableRipple,
4549
RippleAnimationConfig,
50+
RippleGlobalOptions,
4651
RippleRef,
4752
RippleState,
4853
} from '@angular/material/core';
@@ -89,6 +94,9 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
8994
/** The display value of the slider thumb. */
9095
@Input() valueIndicatorText: string;
9196

97+
/** Whether ripples on the slider thumb should be disabled. */
98+
@Input() disableRipple: boolean = false;
99+
92100
/** The MatRipple for this slider thumb. */
93101
@ViewChild(MatRipple) private readonly _ripple: MatRipple;
94102

@@ -99,13 +107,13 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
99107
private _sliderInput: MatSliderThumb;
100108

101109
/** The RippleRef for the slider thumbs hover state. */
102-
private _hoverRippleRef: RippleRef;
110+
private _hoverRippleRef: RippleRef | undefined;
103111

104112
/** The RippleRef for the slider thumbs focus state. */
105-
private _focusRippleRef: RippleRef;
113+
private _focusRippleRef: RippleRef | undefined;
106114

107115
/** The RippleRef for the slider thumbs active state. */
108-
private _activeRippleRef: RippleRef;
116+
private _activeRippleRef: RippleRef | undefined;
109117

110118
/** Whether the slider thumb is currently being pressed. */
111119
private _isActive: boolean = false;
@@ -199,23 +207,23 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
199207
private _showHoverRipple(): void {
200208
if (!this._isShowingRipple(this._hoverRippleRef)) {
201209
this._hoverRippleRef = this._showRipple({ enterDuration: 0, exitDuration: 0 });
202-
this._hoverRippleRef.element.classList.add('mat-mdc-slider-hover-ripple');
210+
this._hoverRippleRef?.element.classList.add('mat-mdc-slider-hover-ripple');
203211
}
204212
}
205213

206214
/** Handles displaying the focus ripple. */
207215
private _showFocusRipple(): void {
208216
if (!this._isShowingRipple(this._focusRippleRef)) {
209217
this._focusRippleRef = this._showRipple({ enterDuration: 0, exitDuration: 0 });
210-
this._focusRippleRef.element.classList.add('mat-mdc-slider-focus-ripple');
218+
this._focusRippleRef?.element.classList.add('mat-mdc-slider-focus-ripple');
211219
}
212220
}
213221

214222
/** Handles displaying the active ripple. */
215223
private _showActiveRipple(): void {
216224
if (!this._isShowingRipple(this._activeRippleRef)) {
217225
this._activeRippleRef = this._showRipple({ enterDuration: 225, exitDuration: 400 });
218-
this._activeRippleRef.element.classList.add('mat-mdc-slider-active-ripple');
226+
this._activeRippleRef?.element.classList.add('mat-mdc-slider-active-ripple');
219227
}
220228
}
221229

@@ -225,7 +233,8 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
225233
}
226234

227235
/** Manually launches the slider thumb ripple using the specified ripple animation config. */
228-
private _showRipple(animation: RippleAnimationConfig): RippleRef {
236+
private _showRipple(animation: RippleAnimationConfig): RippleRef | undefined {
237+
if (this.disableRipple) { return; }
229238
return this._ripple.launch(
230239
{animation, centered: true, persistent: true},
231240
);
@@ -466,8 +475,9 @@ class MatSliderBase {
466475
}
467476
const _MatSliderMixinBase:
468477
CanColorCtor &
478+
CanDisableRippleCtor &
469479
typeof MatSliderBase =
470-
mixinColor(MatSliderBase, 'primary');
480+
mixinColor(mixinDisableRipple(MatSliderBase), 'primary');
471481

472482
/**
473483
* Allows users to select from a range of values by moving the slider thumb. It is similar in
@@ -487,9 +497,10 @@ const _MatSliderMixinBase:
487497
exportAs: 'matSlider',
488498
changeDetection: ChangeDetectionStrategy.OnPush,
489499
encapsulation: ViewEncapsulation.None,
490-
inputs: ['color'],
500+
inputs: ['color', 'disableRipple'],
491501
})
492-
export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnDestroy {
502+
export class MatSlider extends _MatSliderMixinBase
503+
implements AfterViewInit, CanDisableRipple, OnDestroy {
493504
/** The slider thumb(s). */
494505
@ViewChildren(MatSliderVisualThumb) _thumbs: QueryList<MatSliderVisualThumb>;
495506

@@ -592,8 +603,10 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
592603
readonly _cdr: ChangeDetectorRef,
593604
readonly _elementRef: ElementRef<HTMLElement>,
594605
private readonly _platform: Platform,
606+
@Inject(DOCUMENT) document: any,
595607
@Optional() private _dir: Directionality,
596-
@Inject(DOCUMENT) document: any) {
608+
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
609+
readonly _globalRippleOptions?: RippleGlobalOptions) {
597610
super(_elementRef);
598611
this._document = document;
599612
this._window = this._document.defaultView || window;
@@ -724,12 +737,18 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
724737
: 'mdc-slider__tick-mark--inactive';
725738
}
726739

740+
/** Whether the slider thumb ripples should be disabled. */
741+
_isRippleDisabled(): boolean {
742+
return this.disabled || this.disableRipple || !!this._globalRippleOptions?.disabled;
743+
}
744+
727745
static ngAcceptInputType_disabled: BooleanInput;
728746
static ngAcceptInputType_discrete: BooleanInput;
729747
static ngAcceptInputType_showTickMarks: BooleanInput;
730748
static ngAcceptInputType_min: NumberInput;
731749
static ngAcceptInputType_max: NumberInput;
732750
static ngAcceptInputType_step: NumberInput;
751+
static ngAcceptInputType_disableRipple: BooleanInput;
733752
}
734753

735754
/** The MDCSliderAdapter implementation. */

0 commit comments

Comments
 (0)