Skip to content

Commit e939f43

Browse files
committed
feat(material-experimental/mdc-slider): add support for disabling ripples
1 parent 4277c65 commit e939f43

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-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: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
NgZone,
3030
OnDestroy,
3131
OnInit,
32+
Optional,
3233
Output,
3334
QueryList,
3435
ViewChild,
@@ -38,9 +39,14 @@ import {
3839
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
3940
import {
4041
CanColorCtor,
42+
CanDisableRipple,
43+
CanDisableRippleCtor,
4144
MatRipple,
45+
MAT_RIPPLE_GLOBAL_OPTIONS,
4246
mixinColor,
47+
mixinDisableRipple,
4348
RippleAnimationConfig,
49+
RippleGlobalOptions,
4450
RippleRef,
4551
RippleState,
4652
} from '@angular/material/core';
@@ -86,6 +92,9 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
8692
/** The display value of the slider thumb. */
8793
@Input() valueIndicatorText: string;
8894

95+
/** Whether ripples on the slider thumb should be disabled. */
96+
@Input() disableRipple: boolean = false;
97+
8998
/** The MatRipple for this slider thumb. */
9099
@ViewChild(MatRipple) private readonly _ripple: MatRipple;
91100

@@ -96,13 +105,13 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
96105
private _sliderInput: MatSliderThumb;
97106

98107
/** The RippleRef for the slider thumbs hover state. */
99-
private _hoverRippleRef: RippleRef;
108+
private _hoverRippleRef: RippleRef | undefined;
100109

101110
/** The RippleRef for the slider thumbs focus state. */
102-
private _focusRippleRef: RippleRef;
111+
private _focusRippleRef: RippleRef | undefined;
103112

104113
/** The RippleRef for the slider thumbs active state. */
105-
private _activeRippleRef: RippleRef;
114+
private _activeRippleRef: RippleRef | undefined;
106115

107116
/** Whether the slider thumb is currently being pressed. */
108117
private _isActive: boolean = false;
@@ -196,23 +205,23 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
196205
private _showHoverRipple(): void {
197206
if (!this._isShowingRipple(this._hoverRippleRef)) {
198207
this._hoverRippleRef = this._showRipple({ enterDuration: 0, exitDuration: 0 });
199-
this._hoverRippleRef.element.classList.add('mat-mdc-slider-hover-ripple');
208+
this._hoverRippleRef?.element.classList.add('mat-mdc-slider-hover-ripple');
200209
}
201210
}
202211

203212
/** Handles displaying the focus ripple. */
204213
private _showFocusRipple(): void {
205214
if (!this._isShowingRipple(this._focusRippleRef)) {
206215
this._focusRippleRef = this._showRipple({ enterDuration: 0, exitDuration: 0 });
207-
this._focusRippleRef.element.classList.add('mat-mdc-slider-focus-ripple');
216+
this._focusRippleRef?.element.classList.add('mat-mdc-slider-focus-ripple');
208217
}
209218
}
210219

211220
/** Handles displaying the active ripple. */
212221
private _showActiveRipple(): void {
213222
if (!this._isShowingRipple(this._activeRippleRef)) {
214223
this._activeRippleRef = this._showRipple({ enterDuration: 225, exitDuration: 400 });
215-
this._activeRippleRef.element.classList.add('mat-mdc-slider-active-ripple');
224+
this._activeRippleRef?.element.classList.add('mat-mdc-slider-active-ripple');
216225
}
217226
}
218227

@@ -222,7 +231,8 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
222231
}
223232

224233
/** Manually launches the slider thumb ripple using the specified ripple animation config. */
225-
private _showRipple(animation: RippleAnimationConfig): RippleRef {
234+
private _showRipple(animation: RippleAnimationConfig): RippleRef | undefined {
235+
if (this.disableRipple) { return; }
226236
return this._ripple.launch(
227237
{animation, centered: true, persistent: true},
228238
);
@@ -463,8 +473,9 @@ class MatSliderBase {
463473
}
464474
const _MatSliderMixinBase:
465475
CanColorCtor &
476+
CanDisableRippleCtor &
466477
typeof MatSliderBase =
467-
mixinColor(MatSliderBase, 'primary');
478+
mixinColor(mixinDisableRipple(MatSliderBase), 'primary');
468479

469480
/**
470481
* Allows users to select from a range of values by moving the slider thumb. It is similar in
@@ -484,9 +495,10 @@ const _MatSliderMixinBase:
484495
exportAs: 'matSlider',
485496
changeDetection: ChangeDetectionStrategy.OnPush,
486497
encapsulation: ViewEncapsulation.None,
487-
inputs: ['color'],
498+
inputs: ['color', 'disableRipple'],
488499
})
489-
export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnDestroy {
500+
export class MatSlider extends _MatSliderMixinBase
501+
implements AfterViewInit, CanDisableRipple, OnDestroy {
490502
/** The slider thumb(s). */
491503
@ViewChildren(MatSliderVisualThumb) _thumbs: QueryList<MatSliderVisualThumb>;
492504

@@ -586,7 +598,9 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
586598
readonly _cdr: ChangeDetectorRef,
587599
readonly _elementRef: ElementRef<HTMLElement>,
588600
private readonly _platform: Platform,
589-
@Inject(DOCUMENT) document: any) {
601+
@Inject(DOCUMENT) document: any,
602+
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
603+
readonly _globalRippleOptions?: RippleGlobalOptions) {
590604
super(_elementRef);
591605
this._document = document;
592606
this._window = this._document.defaultView || window;
@@ -710,12 +724,18 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
710724
: 'mdc-slider__tick-mark--inactive';
711725
}
712726

727+
/** Whether the slider thumb ripples should be disabled. */
728+
_isRippleDisabled(): boolean {
729+
return this.disabled || this.disableRipple || !!this._globalRippleOptions?.disabled;
730+
}
731+
713732
static ngAcceptInputType_disabled: BooleanInput;
714733
static ngAcceptInputType_discrete: BooleanInput;
715734
static ngAcceptInputType_showTickMarks: BooleanInput;
716735
static ngAcceptInputType_min: NumberInput;
717736
static ngAcceptInputType_max: NumberInput;
718737
static ngAcceptInputType_step: NumberInput;
738+
static ngAcceptInputType_disableRipple: BooleanInput;
719739
}
720740

721741
/** The MDCSliderAdapter implementation. */

0 commit comments

Comments
 (0)