Issue with iOS 11: Keyboard covering a selected text input in Ionic

Problem

Encountering an issue where the keyboard overlaps the text input in a modal when clicked. This problem was identified while testing on an iPhone SE (iOS 11) device.

After researching multiple threads, it seems that Ionic developers have been facing this persistent issue for a while now.

Here are some relevant links related to the problem: Despite trying solutions provided in the following links, none of them seem to work with my code.

Version Information

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.4
Cordova Platforms  : android 6.3.0 ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

ios-deploy : 1.9.2
Node       : v8.9.0
npm        : 5.5.1
OS         : macOS High Sierra
Xcode      : Xcode 9.2 Build version 9C40b

Expected Outcome

The Ion input should remain positioned just above the keyboard as the user types messages.

Current Behavior

https://i.sstatic.net/maRcu.gif

app.component.ts

To avoid navbar crashing issues, keyboard.disableScroll(true); has been implemented within platform.ready(). However, without this line of code, the keyboard functions properly but shifts the entire content upwards including the navbar, causing initial messages to be hidden.

Any suggestions?

UPDATE

Although unsure if my solution is optimal, currently, I've adjusted the margins of the content and footer by considering the initial height of the text area and the keyboard height combined.

If you have a better resolution, feel free to share it as an answer.

Here's the final outcome:

https://i.sstatic.net/ufWFt.gif

Answer №1

In a project with a setup similar to mine, I encountered issues where the iOS keyboard was overlapping the footer bar in Ionic. To fix this issue, I removed

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="60090f0e09034d100c1507090e4d0b0519020f01120420524e524e51">[email protected]</a>
and added
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="47242835232831266a372b32202e296a2e28292e246a2c223e2528263523077569776972">[email protected]</a>
. Check out the plugin website for more information: https://github.com/ionic-team/cordova-plugin-ionic-keyboard.

It turns out that I missed the fact that ionic-plugin-keyboard was deprecated while upgrading from Ionic 1 to 2. Perhaps you were facing a similar situation.

Answer №2

In order to trigger actions, the first step is to determine the height of three specific elements by referring to the provided code example. For instance,

@ViewChild(Content) content: Content;

ionViewDidLoad() {
  if (this.platform.is('ios'))
    this.addKeyboardListeners();

  this.scrollContentElement = this.content.getScrollElement();
  this.footerElement = document.getElementsByTagName('your page component')[0].getElementsByTagName('ion-footer')[0];
  this.inputElement = document.getElementsByTagName('your page component')[0].getElementsByTagName('textarea')[0];
}

Subsequently, establish a keyboard listener tailored for ios platform.

addKeyboardListeners() {
  this.keyboardHideSub = this.keyboard.onKeyboardHide().subscribe(() => {
    let marginBottom = this.textareaHeight - this.initialTextAreaHeight + 44;
    this.renderer.setElementStyle(this.scrollContentElement, 'marginBottom', marginBottom + 'px');
    this.renderer.setElementStyle(this.footerElement, 'marginBottom', '0px')
  });

  this.keybaordShowSub = this.keyboard.onKeyboardShow().subscribe((e) => {
    let newHeight = (e['keyboardHeight']) + this.textareaHeight - this.initialTextAreaHeight;
    let marginBottom = newHeight + 44 + 'px';
    this.renderer.setElementStyle(this.scrollContentElement, 'marginBottom', marginBottom);
    this.renderer.setElementStyle(this.footerElement, 'marginBottom', e['keyboardHeight'] + 'px');
    this.updateScroll(250);
  });
}

Lastly, ensure that you properly unsubscribe from the keyboard listeners before leaving the current page. Create a method specifically for this purpose and invoke it as required.

removeKeyboardListeners() {
  this.keyboardHideSub.unsubscribe();
  this.keybaordShowSub.unsubscribe();
}

Answer №3

@coderroggie's solution was a game-changer for me!

All I had to do was uninstall ionic-plugin-keyboard and then install cordova-plugin-ionic-keyboard - problem solved!

I was dealing with two issues: - In the Chat List, the keyboard would push everything up when I focused on the input (including the navbar).

  • In the Search feature with a top search bar and autocomplete list, the keyboard would overlap the list when the search bar was in focus.

Hats off to @coderroggie for saving the day!

Answer №4

It seems like the issue at hand is related to framework compatibility. I encountered a similar problem on Android and resolved it by utilizing a keyboard plugin along with its functions to manage the viewport height. Here is the code snippet-

constructor(
    private platform: Platform,
    private keyboard: Keyboard
  ) {
    if(this.platform.is('android')){
      this.keyboard.onKeyboardShow().subscribe((e) => {
        var keyboardHeight = e.keyboardHeight;
        if ($("html").hasClass("plt-android")) {
          keyboardHeight = keyboardHeight ? keyboardHeight : '337';
          ****337 is default height to handle if keyboard height not available****
              $('body').css('height', 'calc(100vh - ' + keyboardHeight + 'px)' );
            }
          });

          this.keyboard.onKeyboardHide().subscribe(e => {
            $('input, textarea').blur();
            if ($("html").hasClass("plt-android")) {
                $("body").css("height", "100vh");
            }
          });
    }
}

required libraries--

npm install jquery
npm install @types/jquery
ionic cordova plugin add cordova-plugin-ionic-keyboard
npm install @ionic-native/keyboard

imports--

import { Platform } from '@ionic/angular';
import * as $ from "jquery";
import { Keyboard } from '@ionic-native/keyboard/ngx';

Answer №5

My transformation is complete!

<ion-input type="tel" pattern="tel" autocomplete="tel (ionChange)="writeValue($event.target.value)"></ion-input>

has been upgraded to

<input type="tel" (change)="writeValue($event.target.value)" autocomplete="tel">

Additionally, I've infused it with some fresh styles.

 input {
    width: 100%;
    background-color: transparent;
    border: none;
    font-size: 17px;
    font-weight: 400;
  }
  input:focus {
    outline: none;
  }

Answer №6

At last, our quest for the ideal answer has come to an end.

window.scrollBy(0, 100); // Scroll down by 100 pixels
window.scrollBy(100, 0); // Scroll right by 100 pixels

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transition in the background color of a button while the superfish menu gracefully drops down

I am currently using a customized drop down menu created with Superfish. My goal is to incorporate an independent fade-in effect for the drop down menu. The background color should change on mouseover and the drop-down box should fade in gradually. You ca ...

Do not have the form automatically submit once the barcode scanner has been used

Website Design <form action="product_add_process.php" id="form" method="post" autocomplete="off"> <input type="text" name="product_name[]" /> <input type="button" name="add_product" value="Add More" onClick="addMore();" /> <input ...

Filtering data with React's multiselect checkboxes

I have created an amazing app that fetches a list of todos from this incredible source To enhance user experience, I developed a special CheckBoxDropDown component for selecting todo IDs Within the CheckBoxDropDown.js component, I am passing the onChange ...

The value sent from the ajax call did not reach the PHP file as expected

Here's the code I'm working with: HTML and Javascript: function getValues(){ var filter; $.ajax({ type: "POST", url: "myphpfile.PHP?action=sek", data: "id=1", async: false, suc ...

HAML Error: $ is not defined - Uncaught ReferenceError

I am encountering an issue with the following view: /views/admin/home/index.html.haml = render partial: 'general_tab_partial' .box.boxtab %article %h2= _('Global Reporting') .clearfix = form_tag '#', :method = ...

Counting the total number of lines within a div element

Can someone help me figure out how to accurately determine the number of lines in a div? I tried using this example on jsfiddle, but it's giving me 9 instead of 5. Any suggestions on what might be causing this discrepancy? var lines = document.getEle ...

Steps to making an overlapping sidebar with Bootstrap column

I'm trying to set up a sidebar in Bootstrap that overlaps with a column. The goal is for the sidebar to appear when a button is clicked and disappear when the close button x is clicked. Despite using a Bootstrap row and column layout, I encountered is ...

Retrieving selected item values in Angular 2 using ng2-completer

Recently, I decided to experiment with a new autocompleter tool that is unfamiliar to me: https://github.com/oferh/ng2-completer. I successfully imported it and it seems to be functioning properly. My current goal is to retrieve the values of the selecte ...

Ways to prevent the loading of images during webpage loading

I have encountered an issue with my eCommerce site developed using Laravel 7. Whenever I click on the category page, all product images are being loaded, causing high bandwidth usage. The category "Appereal" contains over 100 products, and although I imple ...

The two-dimensional array in JavaScript has not been defined

I've been trying to troubleshoot the error in my code with no success. I have a simple example of what I believe to be a two-dimensional array, but I keep getting an undefined error. var city = 'London', country = 'England'; ...

The _rfs.scss width rule in Angular-Bootstrap-NgBootstrap is overriding the column width of the col-rules

The Dilemma I am currently working on an Angular project that incorporates Bootstrap and ng-bootstrap. My intention is to utilize the grid system within this project, but I encountered some bugs along the way. When trying to render the following HTML/TS ...

Interacting with the header component within the renderHeader property of the MUI Data Grid Pro will update the sortModel

Currently, I am utilizing the Material UI DataGridPro component to construct a React Js application. I am interested in developing a customized filtering feature. In the image below, you can see a red box representing an IconButton for the filtering view ...

Key name in React.js for disabling CSS selection

I have created a CSS object within my render method and I am attempting to find the key name for making text unselectable. In React.js, they use unique key names such as backgroundColor instead of background-color for CSS objects. Can anyone provide guidan ...

Enhance CKEditor with Linked Select Boxes Plugin

I have ventured into writing a CKEditor Plugin and have grasped the basic concepts. For instance: CKEDITOR.dialog.add( 'addDocumentGroupDialog', function ( editor ) { return { title: 'Link to a document group', min ...

The li elements within a 960.gs layout will not extend to fill the entire width of the

I am still learning about this and I have been following some tutorials online. I managed to make the columns work with paragraph tags, but when I use ul > li tags, the image takes up the entire space. I'm not sure what's causing this issue. ...

Limiting the number of times a specific character appears using a regular expression

Currently, I am in search of a regular expression that allows me to set a limit on the number of times a special character can appear. For instance, if I want to restrict the occurrence of * to a maximum of 5 times in the entire text, then the output shou ...

padding applied exclusively to the Bootstrap column when viewed on a large grid

Can padding be added only for the large grid and not for the medium grid? Large grid with padding: <div class="col-lg-4 pl-3"> </div> Medium grid without padding: <div class="col-md-3"> </div> ...

Is there a method to construct this? It appears quite challenging to create the intricate lines

I want to achieve this specific layout, but I am unsure how to align the lines next to the boxes. Should I use display or position properties to accomplish this? Image illustrating my desired outcome ...

The statement "document.getElementById('grand_total_display').innerHTML = "Total is : $"+variable;" is causing issues in Internet Explorer versions 6 and 7

document.getElementById('grand_total_display).innerHTML = "Total is : $"+variable; seems to be causing an error specifically in IE6 and IE7 Within my HTML, I have an element <li> identified as grand_total_display which contains some existing te ...

iOS: Sketch a message at a specific location within a rectangular shape

My current method for drawing text on the UI involves utilizing the core text API. Despite searching online, most of the results lead me back to the core text API as well. I have gone through various tutorials that explain the process of configuring every ...