Skip to content

Commit

Permalink
fix(tap-click): prevent activated while scrolling
Browse files Browse the repository at this point in the history
fixes #15752
  • Loading branch information
manucorporat committed Sep 25, 2018
1 parent 0379977 commit 7f38d37
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/src/utils/tap-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ export function startTapClick(doc: Document) {
let lastTouch = -MOUSE_WAIT * 10;
let lastActivated = 0;
let cancelled = false;
let scrolling = false;

let activatableEle: HTMLElement | undefined;
let activeDefer: any;

const clearDefers = new WeakMap<HTMLElement, any>();

function onBodyClick(ev: Event) {
if (cancelled) {
if (cancelled || scrolling) {
ev.preventDefault();
ev.stopPropagation();
}
Expand Down Expand Up @@ -45,6 +46,7 @@ export function startTapClick(doc: Document) {

function cancelActive() {
clearTimeout(activeDefer);
activeDefer = undefined;
if (activatableEle) {
removeActivated(false);
activatableEle = undefined;
Expand All @@ -53,14 +55,17 @@ export function startTapClick(doc: Document) {
}

function pointerDown(ev: any) {
if (activatableEle) {
if (activatableEle || scrolling) {
return;
}
cancelled = false;
setActivatedElement(getActivatableTarget(ev), ev);
}

function pointerUp(ev: UIEvent) {
if (scrolling) {
return;
}
setActivatedElement(undefined, ev);
if (cancelled && ev.cancelable) {
ev.preventDefault();
Expand Down Expand Up @@ -133,7 +138,13 @@ export function startTapClick(doc: Document) {
}

doc.body.addEventListener('click', onBodyClick, true);
doc.body.addEventListener('ionScrollStart', cancelActive);
doc.body.addEventListener('ionScrollStart', () => {
scrolling = true;
cancelActive();
});
doc.body.addEventListener('ionScrollEnd', () => {
scrolling = false;
});
doc.body.addEventListener('ionGestureCaptured', cancelActive);

doc.addEventListener('touchstart', onTouchStart, true);
Expand Down

0 comments on commit 7f38d37

Please sign in to comment.