ftlabs / fastclick

Polyfill to remove click delays on browsers with touch UIs
MIT License
18.66k stars 3.22k forks source link

[Safari iOS] Select inputs closes on fast tap since issue #226 fix #268

Open laurentgoudet opened 10 years ago

laurentgoudet commented 10 years ago

The fix for the issue #226 is breaking the select inputs on iOS7 (tested on both iPhone 5 & 5s) for "quick" taps (faster than the 100ms threshold) when the position of the select element on the screen is moved up because the dropdown pops up at the bottom of the screen. If the touchend is not preventDefault(), the element under the initial position of the element (if any) will get the focus, closing the select dropdown.

See video here: http://youtu.be/0J_RNTMzHyQ Test file: http://pastebin.com/hqs3sDB4

If there are no focusable element under to initial on-screen position of the select input it will work fine, as well as if the select input in near the top of the screen and does not move when the dropdown pops up.

The only fixes I found are:

angi- commented 10 years ago

@laurentgoudet I tried your forked version but I still see the same behaviour on selects.

dcalhoun commented 10 years ago

I'm experiencing this issue as well. Would love to see a fix.

sradu commented 10 years ago

+1 having the same issue.

kenvunz commented 10 years ago

thanks @laurentgoudet, your revert fix works for me

Deliaz commented 10 years ago

Have the same: If select not scrolled to center of the screen, after click it looses focus and the focus goes to next or prev input.

Deliaz commented 10 years ago

This works for me:

$('#my-select').on('touchstart',function(e) {
    e.preventDefault();
});

Tested on Safari and Chrome @ iOS7

tonvanalebeek commented 10 years ago

@Deliaz That fixes the issue in iOS, but prevents selects from being used in Chrome on Android for example. (tested @ Nexus4)

mgustafsson1 commented 10 years ago

@laurentgoudet Were you able to find a fix for this? Or did you stick with reverting the mentioned fix?

dcalhoun commented 10 years ago

@mgustafsson1 like @laurentgoudet I rolled back #226 changes on my project and it seems to have resolved the issue for me.

asselin commented 10 years ago

Just submitted a pull request to fix this issue.

mgustafsson1 commented 10 years ago

@asselin Nice, thanks!

avilaton commented 10 years ago

@Deliaz I experience the same issue you mention. Have you found a fix or a workaround? I tryed the fixes sent by @asselin but no luck. Thanks

Deliaz commented 10 years ago

@avilaton https://github.com/ftlabs/fastclick/issues/268#issuecomment-51386550

angi- commented 10 years ago

@Deliaz That may be a fix for those who use jQuery in their project. I am no so fortunate.

Deliaz commented 10 years ago

@angi- event.preventDefault() is a pure JS way

asselin commented 10 years ago

@avilaton Does @Deliaz 's fix work for you? If so, what was the behavior you saw after applying my fix?

asselin commented 10 years ago

@angi- Ditto for my fix-- no jquery required

avilaton commented 10 years ago

@asselin Yes, it does, under certain adaptations to an angular.js app. needsclick does not catch it, I had not time to see why, but the fix should be right there.

oldboyxx commented 9 years ago

As OP said you can exclude selects from fastclick and then it's fine. I didn't manage to do that with "needsclick" class.

I had to add this to the FastClick.prototype.onTouchStart method in fastclick.js

if (targetElement.nodeName.toLowerCase() == "select") {
    return false;
}
contactmatts commented 9 years ago

@oldboyxx thank you, this resolved my issue. I expanded upon it to include native datepickers in mobile scenarios.

var nodeName = targetElement.nodeName.toLowerCase();
var typeAttribute = targetElement.getAttribute('type');

if (nodeName === "select" || (typeAttribute === 'date' && nodeName === "input") || (typeAttribute === 'datetime' && nodeName === "input")) {
    return false;
}
chrisk1 commented 9 years ago

+1 having the same issue. Fixed nicely by solution from @oldboyxx - thank you very much.

serhiisol commented 9 years ago

You can use https://github.com/percolatestudio/fastclick/commit/9ac88ef4653cb1621644ce58080c0696ef9a6598

but return value should be false, as @optikalefx mentioned in that request

davidnormo commented 9 years ago

@contactmatts @oldboyxx Did you put either of your fixes up in a PR?

oldboyxx commented 9 years ago

@davidnormo I did not.

oliver-moran commented 9 years ago

+1 same issue. Made doubly worse it seems when using Angular or dynamicly added selects: the select was totally unselectable unless the user holds down on it for a second or so.

oliver-moran commented 9 years ago

@oldboyxx fix worked for me:

https://github.com/ftlabs/fastclick/issues/268#issuecomment-65022184

Any reason this isn't taken in to the code as a patch (doubt anyone would care about a 300ms delay on selects on iOS)?

amkoehler commented 9 years ago

I'd like to add that the fix provided by @asselin (see pull request here) still is needed in 1.0.6. I added the code from that pull request to my local copy of 1.0.6 and everything is working great.

eiriksm commented 9 years ago

+1 to merging one of the fixes for this issue. Personally I went for the fix from @oldboyxx

malaniz commented 8 years ago

This will be fixed in some version? I'm using this library but is really awful patch every update or new instalation.

Jokerx3 commented 8 years ago

As @laurentgoudet mentioned: Just revert this changes (use "!deviceIsIOS4" in the IF-Statement instead of "!deviceIsIOS") and you will be fine again! =) According to the current version you need to make the changes in the line 584 in fastclick.js . https://github.com/ftlabs/fastclick/pull/235/files

Or simply use my attached modified version =) . But pay attention that this breaks VoiceOver again in some way. fastclick.js.zip

The fix of @oldboyxx didn't work for me as it disabled fastclick.

Danbardo commented 8 years ago

Problem still occurs, @oldboyxx 's fix worked for me, thanks!

davidpelayo commented 8 years ago

This isn't a fastclick issue. It happens in all browsers when RTL and the input is out of the viewport: See this: http://codepen.io/davidpelayo/full/jMjggy/

Tested on latest Firefox, latest Chrome stable and Safari on iOS 10.

array-addu commented 7 years ago

+1 for fix by @oldboyxx

bradennapier commented 7 years ago

so this repo is broken and no plans to fix it i take it thne? this is still a problem years later

bradennapier commented 7 years ago

why would you use something that breaks any input on the page.. .stupid