Skip to content

Commit aba710b

Browse files
committed
feat(material-experimental/mdc-slider): add support for disabling rip… (#22199)
* feat(material-experimental/mdc-slider): add support for disabling ripples
1 parent 8a6565c commit aba710b

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-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: 32 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,10 @@ 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) {
238+
return;
239+
}
229240
return this._ripple.launch(
230241
{animation, centered: true, persistent: true},
231242
);
@@ -466,8 +477,9 @@ class MatSliderBase {
466477
}
467478
const _MatSliderMixinBase:
468479
CanColorCtor &
480+
CanDisableRippleCtor &
469481
typeof MatSliderBase =
470-
mixinColor(MatSliderBase, 'primary');
482+
mixinColor(mixinDisableRipple(MatSliderBase), 'primary');
471483

472484
/**
473485
* Allows users to select from a range of values by moving the slider thumb. It is similar in
@@ -487,9 +499,10 @@ const _MatSliderMixinBase:
487499
exportAs: 'matSlider',
488500
changeDetection: ChangeDetectionStrategy.OnPush,
489501
encapsulation: ViewEncapsulation.None,
490-
inputs: ['color'],
502+
inputs: ['color', 'disableRipple'],
491503
})
492-
export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnDestroy {
504+
export class MatSlider extends _MatSliderMixinBase
505+
implements AfterViewInit, CanDisableRipple, OnDestroy {
493506
/** The slider thumb(s). */
494507
@ViewChildren(MatSliderVisualThumb) _thumbs: QueryList<MatSliderVisualThumb>;
495508

@@ -592,8 +605,10 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
592605
readonly _cdr: ChangeDetectorRef,
593606
readonly _elementRef: ElementRef<HTMLElement>,
594607
private readonly _platform: Platform,
608+
@Inject(DOCUMENT) document: any,
595609
@Optional() private _dir: Directionality,
596-
@Inject(DOCUMENT) document: any) {
610+
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
611+
readonly _globalRippleOptions?: RippleGlobalOptions) {
597612
super(_elementRef);
598613
this._document = document;
599614
this._window = this._document.defaultView || window;
@@ -724,12 +739,18 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
724739
: 'mdc-slider__tick-mark--inactive';
725740
}
726741

742+
/** Whether the slider thumb ripples should be disabled. */
743+
_isRippleDisabled(): boolean {
744+
return this.disabled || this.disableRipple || !!this._globalRippleOptions?.disabled;
745+
}
746+
727747
static ngAcceptInputType_disabled: BooleanInput;
728748
static ngAcceptInputType_discrete: BooleanInput;
729749
static ngAcceptInputType_showTickMarks: BooleanInput;
730750
static ngAcceptInputType_min: NumberInput;
731751
static ngAcceptInputType_max: NumberInput;
732752
static ngAcceptInputType_step: NumberInput;
753+
static ngAcceptInputType_disableRipple: BooleanInput;
733754
}
734755

735756
/** The MDCSliderAdapter implementation. */

0 commit comments

Comments
 (0)