@@ -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,8 @@ 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 ) { return ; }
229
238
return this . _ripple . launch (
230
239
{ animation, centered : true , persistent : true } ,
231
240
) ;
@@ -466,8 +475,9 @@ class MatSliderBase {
466
475
}
467
476
const _MatSliderMixinBase :
468
477
CanColorCtor &
478
+ CanDisableRippleCtor &
469
479
typeof MatSliderBase =
470
- mixinColor ( MatSliderBase , 'primary' ) ;
480
+ mixinColor ( mixinDisableRipple ( MatSliderBase ) , 'primary' ) ;
471
481
472
482
/**
473
483
* Allows users to select from a range of values by moving the slider thumb. It is similar in
@@ -487,9 +497,10 @@ const _MatSliderMixinBase:
487
497
exportAs : 'matSlider' ,
488
498
changeDetection : ChangeDetectionStrategy . OnPush ,
489
499
encapsulation : ViewEncapsulation . None ,
490
- inputs : [ 'color' ] ,
500
+ inputs : [ 'color' , 'disableRipple' ] ,
491
501
} )
492
- export class MatSlider extends _MatSliderMixinBase implements AfterViewInit , OnDestroy {
502
+ export class MatSlider extends _MatSliderMixinBase
503
+ implements AfterViewInit , CanDisableRipple , OnDestroy {
493
504
/** The slider thumb(s). */
494
505
@ViewChildren ( MatSliderVisualThumb ) _thumbs : QueryList < MatSliderVisualThumb > ;
495
506
@@ -592,8 +603,10 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
592
603
readonly _cdr : ChangeDetectorRef ,
593
604
readonly _elementRef : ElementRef < HTMLElement > ,
594
605
private readonly _platform : Platform ,
606
+ @Inject ( DOCUMENT ) document : any ,
595
607
@Optional ( ) private _dir : Directionality ,
596
- @Inject ( DOCUMENT ) document : any ) {
608
+ @Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS )
609
+ readonly _globalRippleOptions ?: RippleGlobalOptions ) {
597
610
super ( _elementRef ) ;
598
611
this . _document = document ;
599
612
this . _window = this . _document . defaultView || window ;
@@ -724,12 +737,18 @@ export class MatSlider extends _MatSliderMixinBase implements AfterViewInit, OnD
724
737
: 'mdc-slider__tick-mark--inactive' ;
725
738
}
726
739
740
+ /** Whether the slider thumb ripples should be disabled. */
741
+ _isRippleDisabled ( ) : boolean {
742
+ return this . disabled || this . disableRipple || ! ! this . _globalRippleOptions ?. disabled ;
743
+ }
744
+
727
745
static ngAcceptInputType_disabled : BooleanInput ;
728
746
static ngAcceptInputType_discrete : BooleanInput ;
729
747
static ngAcceptInputType_showTickMarks : BooleanInput ;
730
748
static ngAcceptInputType_min : NumberInput ;
731
749
static ngAcceptInputType_max : NumberInput ;
732
750
static ngAcceptInputType_step : NumberInput ;
751
+ static ngAcceptInputType_disableRipple : BooleanInput ;
733
752
}
734
753
735
754
/** The MDCSliderAdapter implementation. */
0 commit comments