diff --git a/core/src/utils/gesture/pointer-events.ts b/core/src/utils/gesture/pointer-events.ts index 07ef6f61e3..85ec57a253 100644 --- a/core/src/utils/gesture/pointer-events.ts +++ b/core/src/utils/gesture/pointer-events.ts @@ -30,11 +30,21 @@ export const createPointerEvents = ( if (!rmTouchMove && pointerMove) { rmTouchMove = addEventListener(el, 'touchmove', pointerMove, options); } + + /** + * Events are dispatched on the element that is tapped and bubble up to + * the reference element in the gesture. In the event that the element this + * event was first dispatched on is removed from the DOM, the event will no + * longer bubble up to our reference element. This leaves the gesture in an + * unusable state. To account for this, the touchend and touchcancel listeners + * should be added to the event target so that they still fire even if the target + * is removed from the DOM. + */ if (!rmTouchEnd) { - rmTouchEnd = addEventListener(el, 'touchend', handleTouchEnd, options); + rmTouchEnd = addEventListener(ev.target, 'touchend', handleTouchEnd, options); } if (!rmTouchCancel) { - rmTouchCancel = addEventListener(el, 'touchcancel', handleTouchEnd, options); + rmTouchCancel = addEventListener(ev.target, 'touchcancel', handleTouchEnd, options); } };