@@ -29,6 +29,7 @@ import {
29
29
NgZone ,
30
30
OnDestroy ,
31
31
OnInit ,
32
+ Optional ,
32
33
Output ,
33
34
QueryList ,
34
35
ViewChild ,
@@ -38,9 +39,14 @@ import {
38
39
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
39
40
import {
40
41
CanColorCtor ,
42
+ CanDisableRipple ,
43
+ CanDisableRippleCtor ,
41
44
MatRipple ,
45
+ MAT_RIPPLE_GLOBAL_OPTIONS ,
42
46
mixinColor ,
47
+ mixinDisableRipple ,
43
48
RippleAnimationConfig ,
49
+ RippleGlobalOptions ,
44
50
RippleRef ,
45
51
RippleState ,
46
52
} from '@angular/material/core' ;
@@ -86,6 +92,9 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
86
92
/** The display value of the slider thumb. */
87
93
@Input ( ) valueIndicatorText : string ;
88
94
95
+ /** Whether ripples on the slider thumb should be disabled. */
96
+ @Input ( ) disableRipple : boolean = false ;
97
+
89
98
/** The MatRipple for this slider thumb. */
90
99
@ViewChild ( MatRipple ) private readonly _ripple : MatRipple ;
91
100
@@ -96,13 +105,13 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
96
105
private _sliderInput : MatSliderThumb ;
97
106
98
107
/** The RippleRef for the slider thumbs hover state. */
99
- private _hoverRippleRef : RippleRef ;
108
+ private _hoverRippleRef : RippleRef | undefined ;
100
109
101
110
/** The RippleRef for the slider thumbs focus state. */
102
- private _focusRippleRef : RippleRef ;
111
+ private _focusRippleRef : RippleRef | undefined ;
103
112
104
113
/** The RippleRef for the slider thumbs active state. */
105
- private _activeRippleRef : RippleRef ;
114
+ private _activeRippleRef : RippleRef | undefined ;
106
115
107
116
/** Whether the slider thumb is currently being pressed. */
108
117
private _isActive : boolean = false ;
@@ -196,23 +205,23 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
196
205
private _showHoverRipple ( ) : void {
197
206
if ( ! this . _isShowingRipple ( this . _hoverRippleRef ) ) {
198
207
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' ) ;
200
209
}
201
210
}
202
211
203
212
/** Handles displaying the focus ripple. */
204
213
private _showFocusRipple ( ) : void {
205
214
if ( ! this . _isShowingRipple ( this . _focusRippleRef ) ) {
206
215
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' ) ;
208
217
}
209
218
}
210
219
211
220
/** Handles displaying the active ripple. */
212
221
private _showActiveRipple ( ) : void {
213
222
if ( ! this . _isShowingRipple ( this . _activeRippleRef ) ) {
214
223
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' ) ;
216
225
}
217
226
}
218
227
@@ -222,7 +231,8 @@ export class MatSliderVisualThumb implements AfterViewInit, OnDestroy {
222
231
}
223
232
224
233
/** 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 ; }
226
236
return this . _ripple . launch (
227
237
{ animation, centered : true , persistent : true } ,
228
238
) ;
@@ -463,8 +473,9 @@ class MatSliderBase {
463
473
}
464
474
const _MatSliderMixinBase :
465
475
CanColorCtor &
476
+ CanDisableRippleCtor &
466
477
typeof MatSliderBase =
467
- mixinColor ( MatSliderBase , 'primary' ) ;
478
+ mixinColor ( mixinDisableRipple ( MatSliderBase ) , 'primary' ) ;
468
479
469
480
/**
470
481
* Allows users to select from a range of values by moving the slider thumb. It is similar in
@@ -484,9 +495,10 @@ const _MatSliderMixinBase:
484
495
exportAs : 'matSlider' ,
485
496
changeDetection : ChangeDetectionStrategy . OnPush ,
486
497
encapsulation : ViewEncapsulation . None ,
487
- inputs : [ 'color' ] ,
498
+ inputs : [ 'color' , 'disableRipple' ] ,
488
499
} )
489
- export class MatSlider extends _MatSliderMixinBase implements AfterViewInit , OnDestroy {
500
+ export class MatSlider extends _MatSliderMixinBase
501
+ implements AfterViewInit , CanDisableRipple , OnDestroy {
490
502
/** The slider thumb(s). */
491
503
@ViewChildren ( MatSliderVisualThumb ) _thumbs : QueryList < MatSliderVisualThumb > ;
492
504
@@ -586,7 +598,9 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
586
598
readonly _cdr : ChangeDetectorRef ,
587
599
readonly _elementRef : ElementRef < HTMLElement > ,
588
600
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 ) {
590
604
super ( _elementRef ) ;
591
605
this . _document = document ;
592
606
this . _window = this . _document . defaultView || window ;
@@ -710,12 +724,18 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
710
724
: 'mdc-slider__tick-mark--inactive' ;
711
725
}
712
726
727
+ /** Whether the slider thumb ripples should be disabled. */
728
+ _isRippleDisabled ( ) : boolean {
729
+ return this . disabled || this . disableRipple || ! ! this . _globalRippleOptions ?. disabled ;
730
+ }
731
+
713
732
static ngAcceptInputType_disabled : BooleanInput ;
714
733
static ngAcceptInputType_discrete : BooleanInput ;
715
734
static ngAcceptInputType_showTickMarks : BooleanInput ;
716
735
static ngAcceptInputType_min : NumberInput ;
717
736
static ngAcceptInputType_max : NumberInput ;
718
737
static ngAcceptInputType_step : NumberInput ;
738
+ static ngAcceptInputType_disableRipple : BooleanInput ;
719
739
}
720
740
721
741
/** The MDCSliderAdapter implementation. */
0 commit comments