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

iOS 8.1: Focus on input (filled with text) pushes cursor out of bounds #338

Open
danlevine opened this issue Dec 1, 2014 · 4 comments
Open

Comments

@danlevine
Copy link

Can use http://ftlabs.github.io/fastclick/examples/input.html or http://ftlabs.github.io/fastclick/examples/focus.html to test.

Seems to only show up on iOS 8 Safari. When an input element is filled with text, and then refocused, cursor moves to the end of the text, but incorrectly places the cursor outside of the input's bounds.

This can lead to user confusion, especially when the text string is long enough to push the cursor off-screen.

fastclick_ios8_issue

@danlevine danlevine changed the title iOS 8: Focus on input (filled with text) pushes cursor out of bounds iOS 8.1: Focus on input (filled with text) pushes cursor out of bounds Dec 1, 2014
@jpsalo
Copy link

jpsalo commented Dec 1, 2014

I'm having similar problem with textarea on iOS 8 where focus puts the cursor likewise to the end of the text.

Is it possible to focus to the position where textarea was clicked/tapped?

I managed to set focus into the tapped position with "needsclick" class plus few other hacks like overriding needsFocus implementation, but then of course, I'm getting the delay :) I thought that using "needsfocus" class would solve it, but it did nothing for me in textareas on iOS 8 Safari.

@szpali76
Copy link

I'm having the same problem with an input field, on iOS 8, did you managed somehow to not show the caret out of the input field.
Any help would be appreciated.

Thanks.

@jpsalo
Copy link

jpsalo commented Jan 19, 2015

This it what I did for textarea. See the comments.

FastClick.prototype.needsClick = function(target) {
    case 'textarea':
        if (target.disabled || target.value.length) {
        // Request click when textarea has content.
            return true;
        }

        break;
};
FastClick.prototype.needsFocus = function(target) {
    case 'textarea':
        return !target.value.length;    // Request focus when textarea has no content.
};

What it does is firing a fast click (focus) when textarea is empty and a regular click when there is content.

This way the caret will appear into correct position, which is more important for us than fast click. I did not manage to get the best of both words, meaning fast click and correct caret position but something like this could work for input fields as well

@iberghea
Copy link

iberghea commented Apr 3, 2015

I had the same issue those days but only on IOS 8.1, so maybe my solution will help somebody. The issue came from a div tag which had set a transform CSS property. I solve the problem with the following code:

#your-parent-div {
    -webkit-transform: none;
    -moz-transform: none;
    -o-transform: none;
}

paulfalgout pushed a commit to RoundingWellOS/fastclick that referenced this issue Oct 21, 2015
turtlehat added a commit to turtlehat/fastclick that referenced this issue May 20, 2016
* Fix ftlabs#338 avoid moving cursor to the end of contents when focus on textarea/text

* fix bug: can not clickable when input type is email

* Fix: new input types need a real click

* Add new input types to the needsclick function

* add tests for other input types
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants