Skip to content

Ionic 2 On-Screen Keyboard Covers Focused Input Element Inside Grid Component #10629

Closed

Description

@mikelunn

Ionic version: (check one with "x")
[ ] 1.x
[x ] 2.x

I'm submitting a ... (check one with "x")
[ x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
The onscreen keyboard covers the input element that has focus when used within the grid component.
current-keyboard

Expected behavior:
Given an ion-grid component and a series of ion-row and ion-col components. When an ion-input component resides within an ion-col component, the on-screen keyboard should not cover the input element when it has focus.

The below demo does not use the grid/row/col components.
expected-keyboard

Steps to reproduce:
Use the following code code below to reproduce.

Related code:

<ion-header>
  <ion-navbar color="navbarColor">

    <ion-title><img class="title-image" src="assets/images/mb-logo-w.png"/></ion-title>
    <ion-buttons end>
      <a class="hidden-sm" ion-button color="light" clear href="index.html">
        Start Over
      </a>
      <a class="hidden-lg" ion-button icon-only color="light" clear href="index.html">
        <ion-icon name="power"></ion-icon>
      </a>
    </ion-buttons>
  </ion-navbar>
</ion-header>
<ion-content>
 <ion-grid>
        <ion-row responsive-sm>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text" ></ion-input>
            </ion-item>
          </ion-col>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text" ></ion-input>
            </ion-item>
          </ion-col>
        </ion-row>
        <ion-row responsive-sm>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text"></ion-input>
            </ion-item>
          </ion-col>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text"></ion-input>
            </ion-item>
          </ion-col>
        </ion-row>
        <ion-row responsive-sm>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text"></ion-input>
            </ion-item>
          </ion-col>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text"></ion-input>
            </ion-item>
          </ion-col>
        </ion-row>
        <ion-row responsive-sm>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text" ></ion-input>
            </ion-item>
          </ion-col>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text"></ion-input>
            </ion-item>
          </ion-col>
        </ion-row>
        <ion-row responsive-sm>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text" ></ion-input>
            </ion-item>
          </ion-col>
          <ion-col width-50>
            <ion-item>
              <ion-label color="primary" stacked>First Name</ion-label>
              <ion-input  type="text" ></ion-input>
            </ion-item>
          </ion-col>
        </ion-row>
      </ion-grid>
</ion-content>

Other information:
IOS 10.x. I'm not experiencing the issue in the ionic 2.0.0 environment. Only since i've moved to ionic 2.1.0. I've tried to determine what differences may be present in the generated html, but I do not see any. Ionic-Keyboard plugin is installed with default configuration.

FYI: The issue doesn't occur after rolling back to "ionic-angular": "2.0.0" and "@ionic/app-scripts": "1.0.0"
Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Cordova CLI: 6.5.0 
Ionic Framework Version: 2.1.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.3
ios-deploy version: 1.9.0 
ios-sim version: 5.0.11 
OS: macOS Sierra
Node Version: v6.9.5
Xcode version: Xcode 8.2.1 Build version 8C1002

Activity

  1. AmitMY commented on Mar 3, 2017

    @AmitMY
    Contributor

    I'm having the same problem on Android. Post on forum: https://forum.ionicframework.com/t/android-keyboard-is-over-the-input-doesnt-scroll-to-input/81450

    (There is no new info there, just to show the problem occurs and to supply another buggy case)

  2. mikelunn commented on Mar 3, 2017

    @mikelunn
    Author

    @AmitMY I also posted a question to the forum, as well as the slack channel. I was able to get the markup to function as expected by rolling back dependencies to "ionic-angular": "2.0.0" and "@ionic/app-scripts": "1.0.0"

  3. brunomrpx commented on Mar 7, 2017

    @brunomrpx

    Hi guys. I solved the problem adding the styleposition: initial to ion-col elements. It seems that ion-colhas position: relative and on input focus, the scroll is based on the offsetTop that is relative to the top of the offsetParent node - ion-col in this case. I think that removing this line also solves the problem, but I don't know if it doesn't break something.

  4. AmitMY commented on Mar 7, 2017

    @AmitMY
    Contributor

    @brunomrpx Thanks! Solved for me also.

  5. mikelunn commented on Mar 7, 2017

    @mikelunn
    Author

    @brunomrpx Thanks. Setting position to initial for ion-col elements fixed the scroll issue for me as well. I'm not sure what course of action should be taken at this point. Since this was working in the 2.0.0 release, i'll leave the issue open. Thanks for your help.

  6. dylanvdmerwe commented on Apr 28, 2017

    @dylanvdmerwe
    Contributor

    Note that this is still an issue with release 3.1.0.

  7. manucorporat commented on Apr 28, 2017

    @manucorporat
    Contributor

    Keyboard is a big priority for us, but understand this is complicated. Fortunately I think all issues will be fixed here: https://github.com/driftyco/ionic/pull/11401/files

    plus some native assistance in the latest WK plugin

  8. lfitzgerald commented on Apr 28, 2017

    @lfitzgerald

    @manucorporat Do you know when 11401 will be in a release?

  9. MikeM9999 commented on May 8, 2017

    @MikeM9999

    Setting position to initial for ion-col elements worked also for me, few weeks ago.. but now it doesn't anymore (it's been some time since I last tested this). Anyone else has the same?

  10. mikelunn commented on May 8, 2017

    @mikelunn
    Author

    @MikeMijnheer What changed? Did you upgrade your ionic version?

  11. MikeM9999 commented on May 8, 2017

    @MikeM9999

    Tbh, I cannot think of anything that changed, I didnt upgrade anything. I still have version 2.2.0.
    EDIT: only thing I can think of is that I now runned the application from the .apk (after build), and previously from IonicView app. Both for Android.

    EDIT: Also on IonicView it doesn't work anymore..

  12. lpsantana commented on May 10, 2017

    @lpsantana

    Any solution on this?

  13. viveksinha9 commented on Jun 6, 2017

    @viveksinha9

    Any update on this? Having same problem.

  14. Nightmarepg commented on Jun 6, 2017

    @Nightmarepg

    Im also facing this issue with Android.

  15. 59 remaining items

  16. mhartington commented on Apr 10, 2018

    @mhartington
    Contributor

    @felipegouveiae We have not turned our back on you.

    We've been working on the 4.0 version of Ionic which contains a lot of bug fixes and improvements to the overall framework. This issue is closed as it's been fixed in the next major release.

  17. locked and limited conversation to collaborators on Apr 10, 2018
  18. brandyscarney commented on Apr 10, 2018

    @brandyscarney
    Member

    I just want to chime in here. We realize it looks like we haven't been fixing issues or possibly doing much of anything because of the lack of responses on issues. The framework team is a small team - there are currently 9 of us on the framework (which includes the CLI, documentation, Stencil & more). We have a meeting every Monday morning to discuss our week, and we update our public Ionic Framework Meeting notes so others can see what we're focused on. While we could spend more time responding to issues, this would mean we are spending less time making code fixes. In order to fix a lot of the underlying issues, we made the decision to put all of our focus into the next version.

    Why did we decide to go all in on the next major version? We have spent a lot of our time keeping the framework up-to-date with each release of Angular, trying to decrease startup times, and working on build scripts. The more time we spent on all of this, the less time we had to spend on improving and adding components. In order to solve this, we decided to test out migrating our internal components to use web components. We ended up building a web component compiler called Stencil to make it easier for us to create standards-based web components. What we found is that web components introduce a lot of benefits for both us as open source maintainers and you as an Ionic developer. With the switch to use web components internally startup times have decreased, less code is being shipped, many issues are being fixed indirectly, we are moving towards web standards, we're seeing performance gains that are aligned with Google's requirements for PWAs, we have decoupled ourselves from Angular releases (which means you don't have to wait on us to update!), we've switched to using Angular's tooling and we have gained the ability to support multiple frameworks.

    I want to clarify that adding support for multiple frameworks does not mean we don't still love or support Angular. We are first and foremost supporting Angular, so much so that we have added support for their router and CLI. We're working hard to make the migration as smooth as possible. We recently released a 4.0.0-alpha.0 of @ionic/angular and have so far received a lot of constructive & positive feedback. Hopefully we will have a beta out soon, and with it a blog post with steps to upgrade. Thank you for your understanding.

  19. unlocked this conversation on Apr 10, 2018
  20. renanrlp commented on Apr 30, 2018

    @renanrlp

    Thanks to @Alex0x47! Great solution! In iOS it worked beautifully, but, for me, in Android, the problem persists...
    Would anyone have an idea of what might be happening?

  21. Stephane84 commented on Jun 6, 2018

    @Stephane84

    I also had issues with the keyboard (cordova-plugin-ionic-keyboard) in ionic3.
    Not in grid, but simply in a form with ion-list and ion-item of input
    The keyboard was scrolling over the clicked input.
    I solved it by :
    putting in config.xml :
    <preference name="KeyboardResizeMode" value="ionic" />

    putting in app.module.ts :

    IonicModule.forRoot(MyApp, {
        scrollPadding: false,
        scrollAssist: false,
        autoFocusAssist: false,
    )}
    

    putting in the constructor of app.components.ts :

    window.addEventListener("keyboardDidShow", () => {
        document.activeElement.scrollIntoView(false);
    });
    

    Then, when we click an input, we catch the event fired when the keyboard is shown, and, use js function scrollIntoView on the focused element, to make it visible in the DOM by scrolling the content.

    scrollIntoView can be align to top of scroll-content or at the bottom with the keyboard.

    You can also try to add margin top or bottom at the input by scrolling many px :

    window.addEventListener("keyboardDidShow", () => {
        document.activeElement.scrollIntoView(false);
        
        const elem: HTMLCollectionOf<Element> = document.getElementsByClassName("scroll-content"); // The last content shown, so the current page
        if (elem !== undefined && elem.length > 0) {
            elem[elem.length - 1].scrollTop += 40; // add 40px between the keyboard and the input
        }
    
    });
    
  22. Nytsee commented on Jun 29, 2018

    @Nytsee

    Hey everyone, i've been struggling with this issue for a long time and this line solved it 👍
    page-chat{
    .scroll-content{
    margin-top:50px !important; // the value should be the exacte ion-header height !
    }
    }

  23. hiepxanh commented on Jun 30, 2018

    @hiepxanh
    Contributor

    Ithank you @Nytsee y

  24. maikonigor commented on Aug 15, 2018

    @maikonigor

    the solution proposed by @brunomrpx worked fine for me!

    Obrigado cara! Se eu tivesse perto de ti, te pagava uma cerveja!

  25. atheerahassan commented on Aug 21, 2018

    @atheerahassan

    none of the answers worked for me when I run ionic serve -l. everything just seems to be perfectly fine when I generate it in apk..

  26. rdss-jpupeter commented on Aug 28, 2018

    @rdss-jpupeter

    @Alex0x47 thanks for your approach! Additionally to your solution I have to add the following line to the app.component.ts

    this.keyboard.didShow.subscribe(() =>{ document.activeElement.scrollIntoView(false) })

    keyboard is an instance of Keyboard from '@Ionic-Angular'

  27. MrDrProfX commented on Sep 19, 2018

    @MrDrProfX

    Here's a directive you can slap on to any div container which will auto adjust the marginBottom to account for the keyboard size <div move-up-with-keyboard>...</div>:

    (don't use it on ion-content, that wont work, use it on a div or other normal containers)

    import { Directive, ElementRef } from '@angular/core';
    import { Keyboard } from '@ionic-native/keyboard';
    
    @Directive({
      selector: '[move-up-with-keyboard]' // Attribute selector
    })
    export class MoveUpWithKeyboardDirective {
    
      constructor(private keyboard: Keyboard, private elementRef: ElementRef) {}
    
      ngAfterViewInit() {
        this.keyboard.onKeyboardShow().subscribe(event => {
          this.elementRef.nativeElement.style.marginBottom = event.keyboardHeight + 'px';
        });
        this.keyboard.onKeyboardHide().subscribe(event => {
          this.elementRef.nativeElement.style.marginBottom = '0px';
        });
      }
    }
    
  28. ionitron-bot commented on Nov 7, 2018

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  29. locked and limited conversation to collaborators on Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions