Problem/Motivation

The one major problem most users encountered on mobile devices was the automatic zoom when you focus on a text input. This removed the padding around the edge of the page, making it tricky to scroll without accidentally triggering another input.

Proposed resolution

It's simple to fix. Set all text inputs to 16px

Remaining tasks

Implement the CSS fix
Test

User interface changes

No automatic zoom when focusing on text content

API changes

None

Data model changes

None

Comments

merilainen’s picture

Component: Seven theme » CSS
Assigned: Unassigned » merilainen
Status: Active » Needs review
StatusFileSize
new1.63 KB

This patch will set the font-size to 16px in mobile for both Seven and Bartik themes. I have also made the selector in CKEditor's CSS more specific, because it was overridden with plain body selector.

lewisnyman’s picture

Title: Prevent mobile browsers from zooming on all text inputs » Prevent mobile browsers from zooming on all form inputs
Assigned: merilainen » Unassigned
Status: Needs review » Needs work

Nice investigating. Thanks!

  1. +++ b/core/modules/ckeditor/css/ckeditor-iframe.css
    @@ -11,7 +11,7 @@ body {
    -  body {
    +  .cke_editable {
    

    If we are changing this selector, can we change the one above it outside of the media query so it matches? Then it would be clear they are the same element.

  2. +++ b/core/themes/bartik/css/components/form.css
    @@ -77,9 +77,11 @@ textarea {
    -    font-size: 1.142857143em;
    +    /* Setting font-size to 16px to prevent auto zooming in mobile devices */
    +    font-size: 16px;
    
    +++ b/core/themes/seven/css/components/form.css
    @@ -271,7 +272,8 @@ select {
    -    font-size: 1.2em;
    +    /* Setting font-size to 16px to prevent auto zooming in mobile devices */
    +    font-size: 16px;
    

    I like the comments but could we keep using ems instead of pixels? It's possible to change your base font size in mobile browsers so I think we should maintain the use of ems.

merilainen’s picture

I believe the whole idea of using 16px is to tell the browser to use it strictly without scaling or zooming. That value was already used in the css file, I just made the selector more specific so that it won't be overridden by elements.css.

Here is another patch which unifies the selectors.

merilainen’s picture

Status: Needs work » Needs review
zeeshan_khan’s picture

Status: Needs review » Reviewed & tested by the community

@mErilainen - I agree with #3, changing status to RTBC.

Thanks for the Investigation :)

lewisnyman’s picture

Status: Reviewed & tested by the community » Needs work

I believe the whole idea of using 16px is to tell the browser to use it strictly without scaling or zooming.

This change doesn't just affect zooming, it affects the font size of all inputs in the UI. The UI font size should scale with the user selection, right? If I make my font size really big, the text input font size should also be really big, not just 16px.

merilainen’s picture

Status: Needs work » Needs review
StatusFileSize
new2 KB

So, let's try with em values then.

lewisnyman’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new84.58 KB

Great! Thanks. I can confirm that this prevents zooming on mobile inputs.

wim leers’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/modules/ckeditor/css/ckeditor-iframe.css
    @@ -1,18 +1,18 @@
    -body {
    +.cke_editable {
    ...
    -  body {
    ...
    +  .cke_editable {
    

    Why these selector changes?

  2. +++ b/core/modules/ckeditor/css/ckeditor-iframe.css
    @@ -1,18 +1,18 @@
    -  font-size: 15px;
    +  font-size: 0.9375em;
    

    This feels very brittle.

    Won't this only yield the desired effect in Seven?

  3. +++ b/core/modules/ckeditor/css/ckeditor-iframe.css
    @@ -1,18 +1,18 @@
    -  /* A font-size of 16px prevents iOS from zooming. */
    ...
    -    font-size: 16px;
    

    Why did this not work?

merilainen’s picture

All of your questions have answers in the comments. I'm not experienced core contributor, should I summarize the changes in the description? There aren't that many comments though, yet...
1. CKEditor's ckeditor-iframe.css's plain body selector is currently overridden by elements.css (which comes from Bartik theme, it should be Seven when editing content, right?), which reduces the font-size to under 16px, which in turn makes at least iOS Safari to use auto zoom. Don't know why though.
2. Lewis preferred the use of ems instead of px values, and that is the equivalent to 15px, at least when using Seven.
3. See #2.

wim leers’s picture

AFAICT none of those 3 things were actually said before? In any case: thanks!

  1. Then let's A) use body.cke_editable, because nested editables may also use .cke_editable, B) document why this more specific selector is necessary.
  2. Sorry, I meant to say Bartik, not Seven.
    AFAICT Lewis only asked for em in Bartik's CSS (see #2), not in ckeditor-iframe.css. Lewis, can you chime in here?
lewisnyman’s picture

1. If we have two elements that share the same class, can we use two separate classes instead? It's very fragile, our CSS standards recommend that we use element-agnostic selectors.
2. From what I understand, we shouldn't be using pixels for font sizes anywhere. We don't have official guidelines for this yet, but the decision leans towards ems or rems: #2298015: [policy] Document when we should use each CSS unit

wim leers’s picture

  1. Generally speaking, yes. But this is not a general case. This is an extremely special case. This is for the <body> tag that CKEditor uses in its <iframe>. As I said, CKEditor may actually use the .cke_editable class in a nested manner, so using just the .cke_editable class is dangerous, because it may end up styling unintended elements too!
  2. Okay. But, again, this is a very special case. This CSS is owned by ckeditor.module. Which means it will run in all themes. So, we need the solution that works always, regardless of theme, and thus regardless of other CSS.
    I don't know CSS well enough to be able to say which solution is best to guarantee 16px regardless of theme. But whichever one that is, is the one that should be used.

In short: the normal rules don't apply, just like they don't apply to Toolbar. Because both Toolbar and CKEditor appear in many themes, and Toolbar must always look the same, and so should CKEditor iframe instances. (It is up to themes to specify ckeditor_stylesheets in their .info.yml files to override the defaults, which Bartik already does.)

merilainen’s picture

Here is a new patch which doesn't touch the font-sizes of CKEditor CSS, it only has the more specific selectors.

wim leers’s picture

+++ b/core/modules/ckeditor/css/ckeditor-iframe.css
@@ -1,7 +1,8 @@
+ * that it won't be so easily overriden in theme CSS.

Nit: s/overriden/overridden/

Leaving at NR for Lewis.

merilainen’s picture

Fixed typo.

lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

@Wim Ok great, thanks for addressing my concerns.

@mErilainen Thanks for your work! Even with our nitpicking ;-)

wim leers’s picture

Indeed, thanks! :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: prevent_auto_zoom_in_mobile-2516918-16.patch, failed testing.

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Failed due to a known random fail.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: prevent_auto_zoom_in_mobile-2516918-16.patch, failed testing.

wim leers’s picture

Status: Needs work » Reviewed & tested by the community

Same random fail again. DrupalCI is green.

This is a CSS-only patch, which further proves this is a random failure.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Why are we using px in ckeditor and em in Bartik?

Also could the 1.2307em comment explicitly mention ios? If I google '16px IOS' I get results referring to this magic number. If I google 1.2307em IOS not so much.

wim leers’s picture

Why are we using px in ckeditor and em in Bartik?

AFAIK because Bartik is a theme and chooses to be em-based, whereas the CKEditor iframe CSS is not a theme at all, it's for an iframe after all. The CKEditor iframe CSS is loaded in every CKEditor iframe (non-inline) instance. However, front-end themes can optionally specify "CKEditor stylesheets", to make the CKEditor iframe instance's styling match that on the front-end as closely as possible.

16px is indeed "the magic number".

1.2307em is just the value that is relative to the other em-values in Bartik (container elements' em-value all affect this one; this is the magical value that then corresponds to 16px).


But I'm sure LewisNyman will explain them em-stuff ten times better :)

catch’s picture

16px is indeed "the magic number".

1.2307em is just the value that is relative to the other em-values in Bartik (container elements' em-value all affect this one; this is the magical value that then corresponds to 16px).

Right this is the bit I think needs documenting in once place. So it goes straight from 1.2307em = 16px = magic number for IOS zooming. Not 1.2307em = "no mobile zooming" with no explanation as to why.

Also is 16px a magic number on Android too? Was Android tested?

pazhyn’s picture

StatusFileSize
new535 bytes

There are only two popular hacks to prevent browser scaling for inputs - magic 16px font-size and disabling user scaling.
As 16px is not ok I tried to change viewport.

pazhyn’s picture

Status: Needs work » Needs review
pazhyn’s picture

Issue tags: +dcuacs2015

Status: Needs review » Needs work

The last submitted patch, 28: prevent_auto_zoom_in_mobile-2516918-28.patch, failed testing.

pazhyn’s picture

Assigned: Unassigned » pazhyn
Status: Needs work » Needs review
StatusFileSize
new1.24 KB
dpetruk’s picture

This is good solution and it will fix a lot of different bugs on mobile.
And we must be sure that mobile view is comfortable for all people, because it will remove possibility scaling website.

Also disadvantage of this method it don't supporting Android default browse version < 4.2.
And, please, correct "user-scalable: 0" to "user-scalable: no")

lewisnyman’s picture

Status: Needs review » Needs work

We should not disable user zooming for all Drupal sites. There are two many use cases to assume that a user will never need to zoom. Can we just add a comment to the patch in #16 please?

vulcanr’s picture

I'll be working on that during #Drupalcon2015 Barcelona

vulcanr’s picture

Status: Needs work » Needs review
StatusFileSize
new407 bytes

Made the change, implemented font-size:1.2em (to keep using ems). The previous patch was blocking the general zoom of the site blocking the viewport.

janmilinds’s picture

I'm going to review this issue in DrupalCon mentored sprint

janmilinds’s picture

Status: Needs review » Needs work

I reviewed patch in comment #36 and noticed it didn't work at least on login form as it's keeps zooming the view as I move focus to input field.

vulcanr’s picture

Status: Needs work » Needs review
StatusFileSize
new406 bytes

fixed again, using em's somehow forces the device to zoom, so font-size is 16px. Pending for review.

The last submitted patch, 36: prevent_mobile_browsers-2516918-36.patch, failed testing.

serg2’s picture

The container (div etc) and the font's scaling effects the final font size so in this case 1.2em isn't sufficient to prevent the zoom.
The patch in #16 was pretty solid so might be worth using as a base. It used 1.2307em rather than 1.2em and prevents input zoom on seven, bartik and CKEditor input forms. As far as I understood, it needed some documentation and testing on Android.

lewisnyman’s picture

Status: Needs review » Needs work

This patch is missing a lot of the changes from #16. Is this intentional?

vulcanr’s picture

Because the changes from #16 are used for the ckeditor in the admin panel. The changes in the #39 are for the client side theme. Again, em's are not quite usefull for mobile devices, better to put fixed pixels

vulcanr’s picture

Status: Needs work » Needs review

Please once again, review and test :)

lewisnyman’s picture

I don't want to hold this up but honestly I think it makes a difference here to use pixels instead of ems. It means that the font size won't scale with the chosen font size. If someone increases their font size, then the font size won't increase. Maybe we can use 1rem here to make it less fragile?

vulcanr’s picture

I also tried with rems and it still zooms (at least i tested in an iPhone 6 Plus), but tested at DrupalCon Barcelona with 16px and it doesn't zoom in any device, so, I think that could be nice if someone test the patch, and make the final review to it.

lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

Ok thanks. It sounds like we've exhausted all the possible options. Let's get this bug fixed before RC!

wim leers’s picture

Issue tags: +rc deadline
vulcanr’s picture

thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Discussed with @xjm and given the discussion on-issue and the fact this is a usability improvement that improves mobile forms I think it is okay to commit at this late stage. Credited the UMN 2015 team too.

Committed ab90199 and pushed to 8.0.x. Thanks!

  • alexpott committed ab90199 on 8.0.x
    Issue #2516918 by mErilainen, vulcanr, pazhyn, LewisNyman, Wim Leers,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.