@@ -41,8 +41,8 @@ export class RippleRenderer {
41
41
/** Element which triggers the ripple elements on mouse events. */
42
42
private _triggerElement : HTMLElement | null ;
43
43
44
- /** Whether the mouse is currently down or not. */
45
- private _isMousedown : boolean = false ;
44
+ /** Whether the pointer is currently being held on the trigger or not. */
45
+ private _isPointerDown : boolean = false ;
46
46
47
47
/** Events to be registered on the trigger element. */
48
48
private _triggerEvents = new Map < string , any > ( ) ;
@@ -67,8 +67,12 @@ export class RippleRenderer {
67
67
68
68
// Specify events which need to be registered on the trigger.
69
69
this . _triggerEvents . set ( 'mousedown' , this . onMousedown . bind ( this ) ) ;
70
- this . _triggerEvents . set ( 'mouseup' , this . onMouseup . bind ( this ) ) ;
71
- this . _triggerEvents . set ( 'mouseleave' , this . onMouseLeave . bind ( this ) ) ;
70
+ this . _triggerEvents . set ( 'touchstart' , this . onTouchstart . bind ( this ) ) ;
71
+
72
+ this . _triggerEvents . set ( 'mouseup' , this . onPointerUp . bind ( this ) ) ;
73
+ this . _triggerEvents . set ( 'touchend' , this . onPointerUp . bind ( this ) ) ;
74
+
75
+ this . _triggerEvents . set ( 'mouseleave' , this . onPointerLeave . bind ( this ) ) ;
72
76
73
77
// By default use the host element as trigger element.
74
78
this . setTriggerElement ( this . _containerElement ) ;
@@ -128,7 +132,7 @@ export class RippleRenderer {
128
132
this . runTimeoutOutsideZone ( ( ) => {
129
133
rippleRef . state = RippleState . VISIBLE ;
130
134
131
- if ( ! config . persistent && ! this . _isMousedown ) {
135
+ if ( ! config . persistent && ! this . _isPointerDown ) {
132
136
rippleRef . fadeOut ( ) ;
133
137
}
134
138
} , duration ) ;
@@ -181,17 +185,17 @@ export class RippleRenderer {
181
185
this . _triggerElement = element ;
182
186
}
183
187
184
- /** Listener being called on mousedown event . */
188
+ /** Function being called whenever the trigger is being pressed . */
185
189
private onMousedown ( event : MouseEvent ) {
186
190
if ( ! this . rippleDisabled ) {
187
- this . _isMousedown = true ;
191
+ this . _isPointerDown = true ;
188
192
this . fadeInRipple ( event . pageX , event . pageY , this . rippleConfig ) ;
189
193
}
190
194
}
191
195
192
- /** Listener being called on mouseup event . */
193
- private onMouseup ( ) {
194
- this . _isMousedown = false ;
196
+ /** Function being called whenever the pointer is being released . */
197
+ private onPointerUp ( ) {
198
+ this . _isPointerDown = false ;
195
199
196
200
// Fade-out all ripples that are completely visible and not persistent.
197
201
this . _activeRipples . forEach ( ripple => {
@@ -201,10 +205,19 @@ export class RippleRenderer {
201
205
} ) ;
202
206
}
203
207
204
- /** Listener being called on mouseleave event. */
205
- private onMouseLeave ( ) {
206
- if ( this . _isMousedown ) {
207
- this . onMouseup ( ) ;
208
+ /** Function being called whenever the pointer leaves the trigger. */
209
+ private onPointerLeave ( ) {
210
+ if ( this . _isPointerDown ) {
211
+ this . onPointerUp ( ) ;
212
+ }
213
+ }
214
+
215
+ /** Function being called whenever the trigger is being touched. */
216
+ private onTouchstart ( event : TouchEvent ) {
217
+ if ( ! this . rippleDisabled ) {
218
+ const { pageX, pageY} = event . touches [ 0 ] ;
219
+ this . _isPointerDown = true ;
220
+ this . fadeInRipple ( pageX , pageY , this . rippleConfig ) ;
208
221
}
209
222
}
210
223
0 commit comments