ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Keyboard overlaps the text input when the input is placed inside an <ion-footer>

Open chrskrchr opened this issue 10 years ago • 56 comments

Short description of the problem:

When an <ion-input type="text"> is placed inside an <ion-toolbar> in an <ion-footer>, the iOS keyboard overlaps text inputs placed in an <ion-footer> and the entire page "jumps" when the input receives focus.

keyboard

What behavior are you expecting?

I would expect the text input to be shown above the keyboard so the user can see what they're typing, similar to what happens in the Messages app on iOS. I also wouldn't expect the entire page to jump down immediately after the input receives focus.

Steps to reproduce:

  1. Create a new project with the blank template
  2. Add the following to home.html, run the app on iOS, and focus on the text input
<ion-footer>
    <ion-toolbar>
        <ion-input type="text" placeholder="Add a message..."></ion-input>
    </ion-toolbar>
</ion-footer>

Which Ionic Version? 1.x or 2.x 2.x

Run ionic info from terminal/cmd prompt: (paste output below)

Cordova CLI: 6.2.0 Gulp version: CLI version 3.9.1 Gulp local: Local version 3.9.1 Ionic Framework Version: 2.0.0-beta.10 Ionic CLI Version: 2.0.0-beta.31 Ionic App Lib Version: 2.0.0-beta.17 ios-deploy version: 1.8.6 ios-sim version: 5.0.8 OS: Mac OS X El Capitan Node Version: v4.2.3 Xcode version: Xcode 7.3.1 Build version 7D1014

chrskrchr avatar Jun 30 '16 21:06 chrskrchr

Hello, thanks for opening an issue with us! Would you be able to provide a plunker or repo that demonstrates this issue? Thanks for using Ionic!

jgw96 avatar Jun 30 '16 21:06 jgw96

Here's a .zip of a project that demonstrates the issue.

keyboard.zip

(I removed node_modules directory to reduce its size, so you'll need to run npm install)

chrskrchr avatar Jun 30 '16 21:06 chrskrchr

+1

codespore avatar Jul 07 '16 03:07 codespore

+1

thomas1511 avatar Jul 07 '16 06:07 thomas1511

any news on this?I have the same issue, but not only when the input is in a footer This is a plunker that if built in android device demonstrates the problem http://plnkr.co/edit/GFOUnEeitVpF6o8GSAxU?p=preview

jalef avatar Jul 22 '16 10:07 jalef

any workaround till this gets fixed?

Vasanth19 avatar Aug 13 '16 07:08 Vasanth19

I am having the same issue. I need a fix ASAP. My app is already in production. I have a text input inside an ion-footer-bar It works fine on android. But on IOS the keyboard covers up the text input area.

babinc avatar Aug 14 '16 19:08 babinc

@babinc, My temporary workaround was to replace the <ion-input type="text"> with a plain <input type="text"> and use the following CSS to give it a similar look and feel:

    input.messageDraft {
        width: 100%;
        background-color: transparent;
        border: none;
    }

I haven't seen any negative side effects using a regular input in place of the ion-input.

chrskrchr avatar Aug 15 '16 13:08 chrskrchr

@chrskrchr the nice thing about <ion-input> is it allows the user to "blur" the input when tapping outside on iOS.

**Update Here's the solution I took for <input type="text"/> in the footer-bar not blurring on click-outside.

import {Directive, ElementRef, Output, EventEmitter, HostListener} from '@angular/core';

@Directive({
  selector: '[clickOutside]'
})
export class ClickOutsideDirective {
  constructor(private _elementRef: ElementRef) {
  }

  @Output()
  public clickOutside = new EventEmitter<MouseEvent>();

  @HostListener('document:touchstart', ['$event', '$event.target'])
  public onClick(event: MouseEvent, targetElement: HTMLElement): void {
    if (!targetElement) {
      return;
    }

    const clickedInside = this._elementRef.nativeElement.contains(targetElement);
    if (!clickedInside) {
      this.clickOutside.emit(event);
    }
  }
}

// reference: https://github.com/chliebel/angular2-click-outside With a slight modification I capture the touchstart event rather than click (works on iOS)

<ion-footer (clickOutside)="onClickOutside()">
import { ClickOutsideDirective } from '../../path/to/directive';
import { Keyboard } from 'ionic-native';

@Component({
    directive: [ ClickOutsideDirective ]
})  

public onClickOutside() {
   Keyboard.close()
}

curtisblanchette avatar Aug 29 '16 17:08 curtisblanchette

I am facing the same issue.

kuldeepantil avatar Aug 30 '16 19:08 kuldeepantil

i have same issue. but android is good. this problem only appear ios. i have opend this problem. this problem will resolve at beat12 ?????. when set disableScroll is true, then screen donnot shake, but when keyboard appear, the input at ion footer wlll hidden by keyboard.

tianleios avatar Sep 10 '16 02:09 tianleios

+1

borys avatar Sep 12 '16 15:09 borys

Solution with changing ion-input to input doesn't work for me (ionic beta 11). My workaround, in app.ts, constructor, platform is ready:

if (platform.is('ios')) {
  let 
    appEl = <HTMLElement>(document.getElementsByTagName('ION-APP')[0]),
    appElHeight = appEl.clientHeight;

  Keyboard.disableScroll(true);

  window.addEventListener('native.keyboardshow', (e) => {
    appEl.style.height = (appElHeight - (<any>e).keyboardHeight) + 'px';
  });

  window.addEventListener('native.keyboardhide', () => {
    appEl.style.height = '100%';
  });
}

I'm scaling whole app when keyboard shows - it seems be working. I may add few words from me: when I open app on ios and focus on input in footer - keyboard covers footer. When I lose focus clicking on button (it doesn't happen when click on f.e. header) - keyboard hides, footer goes up first (it is placed above keyboard, when it was opened) and then goes again down (it happens really quickly). It looks like bug is connected with triggering. I hope it helps...

borys avatar Sep 14 '16 10:09 borys

I've posted my similar solution here.

Manduro avatar Sep 15 '16 08:09 Manduro

this happens to me even I'm just using and in ionic v1

flyfj avatar Oct 26 '16 21:10 flyfj

This happens too.

This is work. <ion-input type="text"> -> <input type="text">

This can't work. <ion-input type="text"> -> <div contenteditable='true'></div>

rdlabo avatar Jan 25 '17 11:01 rdlabo

Sadly this is still open in 2.0.0 on iOS devices

corran2go avatar Jan 27 '17 12:01 corran2go

Hello all! We are currently working with the chrome team on this issue. This is a pretty hard problem to solve because it dives into how keyboards interact with webviews, which is all on the native OS side of things. In the meantime there is this plugin https://github.com/EddyVerbruggen/cordova-plugin-native-keyboard which gives you a native chat input that works around the issue.

jgw96 avatar Feb 03 '17 17:02 jgw96

I appreciate that there's a plugin that works around the issue, but that plugin is $199USD, and as far as I can tell doesn't have typings for Ionic 2.

dalemugford avatar Feb 10 '17 02:02 dalemugford

I have the same problem.. any solution yet?

shaarawy130 avatar Mar 27 '17 13:03 shaarawy130