Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

allow event if targetElement does not exist in the DOM anymore #587

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/fastclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,19 @@
touch = event.changedTouches[0];

// Synthesise a click event, with an extra attribute so it can be tracked
clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
clickEvent = new MouseEvent(this.determineEventType(targetElement), {
bubbles: true,
cancelable: true,
screenX: touch.screenX,
screenY: touch.screenY,
clientX: touch.clientX,
clientY: touch.clientY,
ctrlKey: false,
shiftKey: false,
altKey: false,
metaKey: false,
relatedTarget: null
});
clickEvent.forwardedTouchEvent = true;
targetElement.dispatchEvent(clickEvent);
};
Expand Down Expand Up @@ -634,6 +645,12 @@
return true;
}

// If the target element does not exist in the DOM anymore,
// this.targetElement does not refer to anything so we should allow the event since actual target is obviously different
if (!document.contains(this.targetElement)) {
return true;
}

if (event.forwardedTouchEvent) {
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.