Skip to content

Commit

Permalink
Update ngClick.js
Browse files Browse the repository at this point in the history
In our code we have an input element inside a label. The click on the label
generates two clicks, but the second click was not recognised by angular-touch
as a label click, because it only looks at the current element, instead of
looking for a label in parent elements. Therefore, the second click gets
busted, and clicking on the label doesn't do anything for 2500ms.

I added the additional lookup for a containing label inside one of the
conditions inside the onClick method.

Closes angular#11577
  • Loading branch information
mobilabgit authored and petebacondarwin committed Oct 26, 2015
1 parent ffb6b2f commit 7c03150
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ngTouch/directive/ngClick.js
Expand Up @@ -144,7 +144,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
lastLabelClickCoordinates = null;
}
// remember label click coordinates to prevent click busting of trigger click event on input
if (nodeName_(event.target) === 'label') {
if (findUpLabel(event.target)) {
lastLabelClickCoordinates = [x, y];
}

Expand All @@ -163,6 +163,12 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
event.target && event.target.blur && event.target.blur();
}

function findUpLabel(el) {
while (el) {
if (nodeName_(el) === 'label') return true;
el = el.parentNode;
}
}

// Global touchstart handler that creates an allowable region for a click event.
// This allowable region can be removed by preventGhostClick if we want to bust it.
Expand Down

0 comments on commit 7c03150

Please sign in to comment.