iOS textarea text hidden when using -webkit-overflow-scrolling: touch
Asked Answered
T

2

11

Once again I am here because I have exhausted my research on the subject. I have a very simple setup with very simple markup and yet a very strange behavior.

The behavior is eerily similar to (Firefox and Angular: Textarea placeholder doesn't appear until first focus) but I am experiencing it in a different environment.

Consider the snippet with a readonly text area. This brings bad a list of comments, where 2-3 fit on the screen before having to scroll for some more already loaded comments.

    <div class="row">
        <div class="col-xs-2 text-right font-sm-dark"
             style="height:20px; line-height:20px; font-weight:bold;">
            <label>Comment:</label>
        </div>
        <div class="col-xs-10 text-left font-sm">
            <div class="col-xs-12 text-left font-sm">
                <textarea style="text-align:left; width:100%; padding:0,0; line-height:normal; resize:none;"
                          rows="5"
                          ng-model="comment.Text"
                          readonly></textarea>
            </div>
         </div>
    </div>

This works great when running the application on the browser (chrome, safari, etc), but once I build the application using PhoneGap and run it on the ipad device I get the following behavior:

The comments visible already show fine in the textareas. When I scroll down do read more comments, their textareas are empty BUT if I tap the textarea then the text appears.

Already visible textareas showing their text

After scrolling, the Comment boxes are empty until "tapped" in iOS.

That is it, there is no complicated CSS related to this markup, and no weird server loading issues. When this area loads it brings all the comments with it.

I'd like to point out that this is a large mobile app with much more sophisticated markup/functionality that works fine on the browser and translates perfectly to both Android and iOS mobile apps.

The first link I posted upthere leads me to think that there is some weird bug in ng-touch handling textarea focus on mobile clients.

Any ideas? I'd hate to dump textareas for text inputs, but I am almost at that point.

Teeters answered 25/2, 2015 at 21:35 Comment(2)
finally found some guys talking about pretty much the same thing. This has to do with an inertia scrolling issue. #8111080Teeters
Not specific to Angular or textareas, exhibited with React and inputsDynamiter
T
28

This issue is triggered by the textarea element within a container using:

-webkit-overflow-scrolling: touch 

in its parent container.

Removing the class solves the problem with the 'initially hidden text not loading' but losing desired inertia scrolling UX.

Adding

-webkit-transform: translateZ(0px) 

to the style of my affected textarea elements solves my problem.

In my particular case I dont believe I will incur in prohibitive performance penalties since my hidden elements that I am yet to scroll to wouldnt be loading rich content (videos/animations/etc) that would tax the VRAM on the mobile device. I am basically taking advantage of the additional rendering context (hardware assisted) being triggered by this, which makes my text render normally, and thus bypassing an iOS BUG.

Great information on translateZ (and its close cousin translate3d(0,0,0)) http://aerotwist.com/blog/on-translate3d-and-layer-creation-hacks/

Teeters answered 2/3, 2015 at 21:22 Comment(1)
I found that it was triggered by having a bunch of images above the inputs. I think it's just a rendering issue with there being too much to render and the translateZ activates hardware acceleration.Proscribe
I
1

It seems that when using:

-webkit-overflow-scrolling: touch;

iOS places the form elements in an odd z-index placement where it is visually hidden yet still clickable (knowing where the elements are: can type text, press buttons, etc). The hack-fix until iOS corrects this bug (which is present in both Safari and Chrome on iOS) is to explicitly set a lower z-index on all elements with -webkit-overflow-scrolling: touch set.

For example, if the page doesn't use z-index at all then using:

z-index: -1; -webkit-transform: translateZ(-1); -webkit-overflow-scrolling: touch;

will correct the issue.

Intwine answered 29/10, 2018 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.