@@ -40,9 +40,14 @@ import {
40
40
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
41
41
import {
42
42
CanColorCtor ,
43
+ CanDisableRipple ,
44
+ CanDisableRippleCtor ,
43
45
MatRipple ,
46
+ MAT_RIPPLE_GLOBAL_OPTIONS ,
44
47
mixinColor ,
48
+ mixinDisableRipple ,
45
49
RippleAnimationConfig ,
50
+ RippleGlobalOptions ,
46
51
RippleRef ,
47
52
RippleState ,
48
53
} from '@angular/material/core' ;
@@ -89,6 +94,9 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
89
94
/** The display value of the slider thumb. */
90
95
@Input ( ) valueIndicatorText : string ;
91
96
97
+ /** Whether ripples on the slider thumb should be disabled. */
98
+ @Input ( ) disableRipple : boolean = false ;
99
+
92
100
/** The MatRipple for this slider thumb. */
93
101
@ViewChild ( MatRipple ) private readonly _ripple : MatRipple ;
94
102
@@ -99,13 +107,13 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
99
107
private _sliderInput : MatSliderThumb ;
100
108
101
109
/** The RippleRef for the slider thumbs hover state. */
102
- private _hoverRippleRef : RippleRef ;
110
+ private _hoverRippleRef : RippleRef | undefined ;
103
111
104
112
/** The RippleRef for the slider thumbs focus state. */
105
- private _focusRippleRef : RippleRef ;
113
+ private _focusRippleRef : RippleRef | undefined ;
106
114
107
115
/** The RippleRef for the slider thumbs active state. */
108
- private _activeRippleRef : RippleRef ;
116
+ private _activeRippleRef : RippleRef | undefined ;
109
117
110
118
/** Whether the slider thumb is currently being pressed. */
111
119
private _isActive : boolean = false ;
@@ -199,23 +207,23 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
199
207
private _showHoverRipple ( ) : void {
200
208
if ( ! this . _isShowingRipple ( this . _hoverRippleRef ) ) {
201
209
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' ) ;
203
211
}
204
212
}
205
213
206
214
/** Handles displaying the focus ripple. */
207
215
private _showFocusRipple ( ) : void {
208
216
if ( ! this . _isShowingRipple ( this . _focusRippleRef ) ) {
209
217
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' ) ;
211
219
}
212
220
}
213
221
214
222
/** Handles displaying the active ripple. */
215
223
private _showActiveRipple ( ) : void {
216
224
if ( ! this . _isShowingRipple ( this . _activeRippleRef ) ) {
217
225
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' ) ;
219
227
}
220
228
}
221
229
@@ -225,7 +233,10 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
225
233
}
226
234
227
235
/** 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
+ }
229
240
return this . _ripple . launch (
230
241
{ animation, centered : true , persistent : true } ,
231
242
) ;
@@ -466,8 +477,9 @@ class MatSliderBase {
466
477
}
467
478
const _MatSliderMixinBase :
468
479
CanColorCtor &
480
+ CanDisableRippleCtor &
469
481
typeof MatSliderBase =
470
- mixinColor ( MatSliderBase , 'primary' ) ;
482
+ mixinColor ( mixinDisableRipple ( MatSliderBase ) , 'primary' ) ;
471
483
472
484
/**
473
485
* Allows users to select from a range of values by moving the slider thumb. It is similar in
@@ -487,9 +499,10 @@ const _MatSliderMixinBase:
487
499
exportAs : 'matSlider' ,
488
500
changeDetection : ChangeDetectionStrategy . OnPush ,
489
501
encapsulation : ViewEncapsulation . None ,
490
- inputs : [ 'color' ] ,
502
+ inputs : [ 'color' , 'disableRipple' ] ,
491
503
} )
492
- export class MatSlider extends _MatSliderMixinBase implements AfterViewInit , OnDestroy {
504
+ export class MatSlider extends _MatSliderMixinBase
505
+ implements AfterViewInit , CanDisableRipple , OnDestroy {
493
506
/** The slider thumb(s). */
494
507
@ViewChildren ( MatSliderVisualThumb ) _thumbs : QueryList < MatSliderVisualThumb > ;
495
508
@@ -592,8 +605,10 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
592
605
readonly _cdr : ChangeDetectorRef ,
593
606
readonly _elementRef : ElementRef < HTMLElement > ,
594
607
private readonly _platform : Platform ,
608
+ @Inject ( DOCUMENT ) document : any ,
595
609
@Optional ( ) private _dir : Directionality ,
596
- @Inject ( DOCUMENT ) document : any ) {
610
+ @Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS )
611
+ readonly _globalRippleOptions ?: RippleGlobalOptions ) {
597
612
super ( _elementRef ) ;
598
613
this . _document = document ;
599
614
this . _window = this . _document . defaultView || window ;
@@ -724,12 +739,18 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
724
739
: 'mdc-slider__tick-mark--inactive' ;
725
740
}
726
741
742
+ /** Whether the slider thumb ripples should be disabled. */
743
+ _isRippleDisabled ( ) : boolean {
744
+ return this . disabled || this . disableRipple || ! ! this . _globalRippleOptions ?. disabled ;
745
+ }
746
+
727
747
static ngAcceptInputType_disabled : BooleanInput ;
728
748
static ngAcceptInputType_discrete : BooleanInput ;
729
749
static ngAcceptInputType_showTickMarks : BooleanInput ;
730
750
static ngAcceptInputType_min : NumberInput ;
731
751
static ngAcceptInputType_max : NumberInput ;
732
752
static ngAcceptInputType_step : NumberInput ;
753
+ static ngAcceptInputType_disableRipple : BooleanInput ;
733
754
}
734
755
735
756
/** The MDCSliderAdapter implementation. */
0 commit comments