fix(gesture): onEnd now correctly fires even if the event target was removed from the DOM (#23713)

resolves #22819 

Co-authored-by: Falingorn <falingorn@users.noreply.github.com>
This commit is contained in:
Liam DeBeasi
2021-08-02 13:47:27 -04:00
committed by GitHub
parent 792864f8ab
commit 4edb5e2fed

View File

@ -30,11 +30,21 @@ export const createPointerEvents = (
if (!rmTouchMove && pointerMove) { if (!rmTouchMove && pointerMove) {
rmTouchMove = addEventListener(el, 'touchmove', pointerMove, options); 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) { if (!rmTouchEnd) {
rmTouchEnd = addEventListener(el, 'touchend', handleTouchEnd, options); rmTouchEnd = addEventListener(ev.target, 'touchend', handleTouchEnd, options);
} }
if (!rmTouchCancel) { if (!rmTouchCancel) {
rmTouchCancel = addEventListener(el, 'touchcancel', handleTouchEnd, options); rmTouchCancel = addEventListener(ev.target, 'touchcancel', handleTouchEnd, options);
} }
}; };