emberjs-touch icon indicating copy to clipboard operation
emberjs-touch copied to clipboard

Breaks checkbox click (and other situations?)

Open natevw opened this issue 11 years ago • 1 comments

The touch.enabled timeout isn't a very good solution to avoiding extra clicks. By returning false from the "second" click, you cause jQuery to preventDefault() its event handling. But the "second" click is sometimes just the same click being bubbled up to a parent view.

E.g. if I add a log right above where this logic is happening I see this for a single click on a checkbox:

Handling click in <Ember.Checkbox:ember713> touch.enabled: true        ember-fastclick.js:98
Handling click in <Ember.View:ember696> touch.enabled: false        ember-fastclick.js:98

So the second call sees touch disabled, and returns false. This prevents default on the click which prevents the checkbox from being triggered! There are probably other situations where this can cause trouble, but this is the most apparent in an app I am helping with.

Shouldn't the evt.preventDefault() in your "touchend" handler already prevent the browser from sending its own click duplicating the simulated one? Or why exactly was a2fc30e230a0b0ae75fe36351c3997385d3c7c18 added?

natevw avatar Nov 08 '13 22:11 natevw

One workaround that leaves your current logic mostly intact (it doesn't seem right but OTOH I don't know what it's trying to accomplish) is to simply add an intial timeout to the touch disable setting like so:

// Temporarily disable touch to prevent duplicate clicks
function disableTouch() {
    if (touch.enabled) setTimeout(function () {
        touch.enabled = false;
        setTimeout(function() {
            touch.enabled = true;
        }, 400);
    }, 0);      // HACK: timeout is a workaround for https://github.com/JamesHight/emberjs-touch/issues/2
}

natevw avatar Nov 08 '13 22:11 natevw