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

Is there any update on this issue yet please? I first raised this with @mhartington a while ago and this really has been a very longstanding issue now.

I put a lot of effort into demonstrating the issue here (https://github.com/driftyco/ionic/issues/5432 ) but it seems that this has been close for a while.

Ionic team - this is a really important issue for my apps - please can we have an update.

Apologies if I am unaware of a fix or workaround that has gone in.

Look forward to hearing from you.

alexmady avatar Apr 14 '17 18:04 alexmady

I'm my particular situation I had an input in .bar-footer. The following CSS seemed to fix the issue:

body.keyboard-open.platform-ios .bar-footer {
    bottom: 36px;
}

NOTE: There is a bit of a delay before .bar-footer jumps up above the keyboard because of there being a delay before the .keyboard-open class gets attached to the body.

But then when you start typing you'll notice that your text isn't reflecting in the input field. That's thanks to the "fix" Ionic puts in place for "some keyboard issues while scrolling". To disable this you can do the following:

window.ionic.tap.cloneFocusedInput = function () {
    return null;
};

That will overwrite and disable cloned inputs. After that, everything seemed to be working fine.

deangibson89 avatar Apr 20 '17 12:04 deangibson89

Thanks @Tiwaz89 - any idea how to get the keyboard to stay open in-between messages. Problem demonstrated in gif below.

Also both autocomplete and spellcheck options for the ion-input do not work....

keyboard

alexmady avatar Apr 20 '17 16:04 alexmady

Found a solution here: https://stackoverflow.com/questions/32730171/ionic-footer-input-field-being-hidden-by-keyboard-in-chat-app

set fullscreen property to value false in config.xml

This goes out out to anyone that's had a similar problem with the ionic footer and inputs in cordova build. If you have this preference in config.xml

<preference name="fullscreen" value="true" />

The keyboard will hide the input when it's activated. If you absolutely need to see that input when typing (that was a joke) than just set it to false and it should solve the problem.

blacksmith77 avatar May 31 '17 11:05 blacksmith77

Anything better than a workaround or third-party solution?

mastronaute avatar Jun 06 '17 09:06 mastronaute

@Tiwaz89 : Can you please help where I need to place this code? window.ionic.tap.cloneFocusedInput = function () { return null; }; I am currently facing lag during the input as the footer takes time to appear on top of keyboard.

kiranNegiloni avatar Aug 31 '17 01:08 kiranNegiloni

This worked for me, assuming all you ion-input are wrapped with ion-content. Pure JS works with Typescript as well.

  var ionInputs = document.querySelectorAll("ion-input");
  Array.prototype.forEach.call(ionInputs, function (e) {
    e.addEventListener("focus", function (e) {
      let scroll=this.offsetTop;

/*somehow this doesnt work when keyboard is showing up, so have to wait till it is shown . You can also use native keyboard plugin and use the native event:
window.addEventListener('native.keyboardshow')*/  
        setTimeout(()=>{this.closest(".scroll-content").scrollTop=scroll},400); 
    }, true);
  })

justgeek avatar Sep 19 '17 14:09 justgeek

I am resolved this bug with my logic for all ionic 1 and ionic 2 var old_height = window.innerHeight; $scope.checkheight = function(){ console.log("BEFORE window.innerHeight",window.innerHeight) var new_height = window.innerHeight; var keyboard_height = (old_height - new_height) ; $('.bar-footer').css('bottom',keyboard_height+'px') keyboard_height = (keyboard_height + 50) ; $('.chat-main').css('bottom',keyboard_height+'px') $ionicScrollDelegate.scrollBottom(); } keyboard = $interval(function () { $scope.checkheight(); }, 300);

Call this function into interval interval always check your keyboard height and showing your keyboard with input Thanks

sohandhaindwal avatar Sep 20 '17 06:09 sohandhaindwal

take care using intervals, @sohandhaindwal you can degrade app performance...

jdnichollsc avatar Sep 20 '17 18:09 jdnichollsc

@jdnichollsc I was just give a logic , you can achieve this without interval. like on focus or etc.

sohandhaindwal avatar Oct 03 '17 07:10 sohandhaindwal

It is fixed?

onedou avatar Nov 24 '17 12:11 onedou

so I am still having this problem, any fix?

yaozuwang avatar Dec 08 '17 05:12 yaozuwang

This directive worked for me at iOS11 & iPhoneX.

https://gist.github.com/rdlabo/57bb9a2098f2f83c2c1cc16c8e88f6d5

rdlabo avatar Dec 08 '17 05:12 rdlabo

@rdlabo Thanks, i just tried that, it works great, but the header seems to slide with the content initially, is that how it works?

yaozuwang avatar Dec 08 '17 05:12 yaozuwang

the header seems to slide with the content initially

@yaozuwang Sorry. I can't fix this problem... I expect you will fix !

rdlabo avatar Dec 08 '17 06:12 rdlabo

@rdlabo lol ok hahaha

yaozuwang avatar Dec 08 '17 06:12 yaozuwang

@rdlabo , @yaozuwang , @onedou use ionic cordova-plugin-ionic-webview plugin for this issue ionic 2 provide default but ionic 1 not so you have to manually install this thanks

sohandhaindwal avatar Dec 08 '17 09:12 sohandhaindwal

Any solutions for this issue guys?

jeffminsungkim avatar Dec 22 '17 21:12 jeffminsungkim

I could not reproduce the error, but I have a bad result when the keyboard is changed to "emoji". The keyboard height is bigger then, overlaps the input and does not push it up at all.

andreas-aeschlimann avatar Dec 23 '17 01:12 andreas-aeschlimann

@jgw96 you said quite some time ago that you are looking into the issue with the chrome dev team. Has there been any more insights?

BorntraegerMarc avatar Dec 28 '17 11:12 BorntraegerMarc