Skip to content

Auto hide tabs when keyboard is open #7047

Closed

Description

@RaymondAtivie

When the keyboard is opened in a tabs page (position=bottom), the tabs appear on top of the keyboard.

The expected behavior is to hide the tabs when the keyboard is visible

Steps to reproduce:

  1. Create a starter tabs template
  2. Include an ion-input in the page
  3. Run it on a device and focus on the input element

Maybe a CSS class can be added to the page when the keyboard is open (.keyboard-is-open) so that the behavior can be controlled

This issue is for Ionic 2

Cordova CLI: 5.2.0
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.9
Ionic CLI Version: 2.0.0-beta.30
Ionic App Lib Version: 2.0.0-beta.16
OS:
Node Version: v4.3.2

Activity

  1. self-assigned this
    on Jun 25, 2016
  2. mpaland commented on Jun 25, 2016

    @mpaland

    Yeah, I assume you're under Android. The old keyboard problem...

    I saw a talk on PhoneGap conf of @tlancina about the keyboard and it seems to be a pretty hard issue in general!
    I can confirm that the bottom tab bar is pushed up upon opening the keyboard in my app under Android, too. But much more worse is covering input fields which are near the bottom. Tim said, one should try to avoid that, but unfortunately there are long lists to edit in my project.
    I have postponed the whole keyboard topic to wait and see how it plays out in ionic.

    Besides, @tlancina, is there a best practice tutorial about using the keyboard in ionic (integrating the ionic keyboard plugin, init/setting event handlers)?

  3. tlaverdure commented on Jul 14, 2016

    @tlaverdure
    Contributor

    I am experiencing this issue as well.

  4. masimplo commented on Jul 19, 2016

    @masimplo
    Contributor

    We are having the same issue in our project too. Any plans regarding this?

  5. covveadmin commented on Jul 28, 2016

    @covveadmin

    Hey guys, also feeling the pain - any news by any chance?

  6. theromis commented on Aug 12, 2016

    @theromis

    also need this great feature, tabs and may be even header nice to be able to hide.

  7. masimplo commented on Aug 12, 2016

    @masimplo
    Contributor

    @jgw96 I noticed you added the enhancement label on this. Since native apps do no behave the same (moving tabs above the keyboard) and the tabs are also limit the actual content real estate to just a couple lines, especially on smaller phones, shouldn't this be consider a more serious issue?

  8. bvx89 commented on Sep 2, 2016

    @bvx89

    For people looking for a temporary solution, here's what I did:

    TabsComponent constructor:

    platform.ready().then(() => {
                Keyboard.onKeyboardShow().subscribe(() => {
                    document.body.classList.add('keyboard-is-open');
                });
    
                Keyboard.onKeyboardHide().subscribe(() => {
                    document.body.classList.remove('keyboard-is-open');
                });
    });
    

    Inside the CSS:

    body.keyboard-is-open ion-tabbar {
      display: none;
    }
    
    body.keyboard-is-open scroll-content {
      margin-bottom: 0 !important;
    }
    

    This won't work if you have multiple tabs on a page, but I guess you can select them with your CSS directly.

    I'm currently running Ionic beta 11

  9. RaymondAtivie commented on Oct 7, 2016

    @RaymondAtivie
    Author

    any update on this?

  10. RaymondAtivie commented on Oct 7, 2016

    @RaymondAtivie
    Author

    @bvx89 Thanks.
    For the sake of those on Rc0 there's a slight change on the css

    body.keyboard-is-open .tabbar {
      display: none;
    }
    
    body.keyboard-is-open .scroll-content {
      margin-bottom: 0 !important;
    }
    

    No official solution yet tho

  11. jeanbaptistevilain commented on Nov 27, 2016

    @jeanbaptistevilain

    Just to mention that enabling Fullscreen mode on Android also fixes this issue for me.
    This can be done by setting
    <preference name="Fullscreen" value="true" />
    in config.xml, and optionally adding cordova-plugin-fullscreen if you're using a cordova android platform older than v5.0.0.

  12. masimplo commented on Nov 27, 2016

    @masimplo
    Contributor

    Is this going to be fixed in the next version along with the rest of keyboard issues that are going to be fixed (read something stating that about keyboard issues in another thread) or has this fallen between the cracks?

  13. 39 remaining items

  14. RicardoBer commented on Sep 13, 2017

    @RicardoBer

    I do not have courage to go more than ionic v1.

    I make this patch (I put in a the controller of affected view, as I only have one with this combo).

    /* HACK Al mostrar el teclado el tabbar se pone encima de él en android*/
    var bottom_stored=0;
    window.addEventListener('native.keyboardshow', function (e) {
    angular.element(document.getElementsByClassName('tab-nav')).addClass('hide');
    bottom_stored = angular.element(document.getElementsByClassName('has-tabs')).css('bottom');
    angular.element(document.getElementsByClassName('has-tabs')).css('bottom','0px');
    $scope.$apply();
    });
    window.addEventListener('native.keyboardhide', function (e) {
    angular.element(document.getElementsByClassName('tab-nav')).removeClass('hide');
    angular.element(document.getElementsByClassName('has-tabs')).css('bottom',bottom_stored);
    $scope.$apply();
    });
    /* HACK */

    this works

  15. Jatapiaro commented on Sep 29, 2017

    @Jatapiaro

    In my case this only happens when I'm using android, the best solution is change a property on the android tag in config.xml

    <platform name="android"> <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity"> <activity android:windowSoftInputMode="adjustPan" /> </edit-config>

    Just simple add the following lines, so the android build in the AndroidManifest.xml have the adjustPan in android:windowSoftInputMode, this will cause that the keyboard overlays all the content instead of pushing the screen up.

  16. pablogarciamiranda commented on Nov 29, 2017

    @pablogarciamiranda

    For the approach of @Jatapiaro explained above, I have installed the following cordova plugin:

    cordova plugin add cordova-custom-config

    Then I have just added the following to my config.xml

    <platform name="android">
        <preference name="android-manifest/application/activity/@android:windowSoftInputMode" value="adjustPan" />
        ...
    </platform>
    

    Working on Android & iOS

  17. martingitehi commented on Dec 15, 2017

    @martingitehi

    Here is what I did to hide keyboard dynamically:

    in my TS file:

    @ViewChild('foot') foo_ter: ElementRef;
      constructor(private platform: Platform, private keyboard: Keyboard) {
        this.platform.ready().then(() => {
          this.keyboard.onKeyboardShow().subscribe(() => {
            this.foo_ter.nativeElement.hidden = true;
          });
          this.keyboard.onKeyboardHide().subscribe(() => {
            this.foo_ter.nativeElement.hidden = false;
          });
        });
      }
    

    then in my HTML file, I make a template variable called #footer which is what I am referencing in the TS above like this:

    <ion-footer no-border style="padding:5%;" #footer>
      <ion-item no-lines>
       Don't have an account?
        <button ion-button style="text-align:center;" bold item-end clear no-lines clear (click)="signup()">
          Sign Up
        </button>
      </ion-item>
    </ion-footer>
    

    I hope it works for you too :-) @RaymondAtivie

  18. abishekg commented on Jun 5, 2018

    @abishekg

    I gave it this way in Ionic V3. Works perfectly fine.
    TS file
    ionViewDidEnter() {
    if (this.keyboard.isOpen())
    this.showTabs = false;
    else
    this.showTabs = true;
    }

    HTML file
    <ion-tabs *ngIf="showTabs" #myTabs>

  19. senturkhasan commented on Jun 5, 2018

    @senturkhasan

    dasda

    asd

  20. senturkhasan commented on Jun 5, 2018

    @senturkhasan

    not true answer

  21. jayzyaj commented on Jun 26, 2018

    @jayzyaj

    Is there any update on the official solution for this?

  22. dharapvj commented on Jun 27, 2018

    @dharapvj

    As of today.. with Ionic v
    I could not get @ionic-native/keyboard to work. As many others stated.. onKeyboardShow() event never fires.
    also cordova-keyboard-plugin has been deprecated.

    So what worked for me was...

    cordova plugin add cordova-plugin-ionic-keyboard --save
    

    post this.. I added window.addEventListener as described in their readme

    don't forget to remove the eventlistener in case you leave the tab page and come back to it again..

    // MyTabs.ts
      showListener() {
        console.log('keyboard visible');
        document.body.classList.add('keyboard-is-open');
      }
      hideListener() {
        console.log('keyboard hides');
        document.body.classList.remove('keyboard-is-open');
      }
    
    
      ionViewDidEnter() {
        window.addEventListener('keyboardWillShow', this.showListener);
        window.addEventListener('keyboardDidHide', this.hideListener);
      }
    
      ionViewWillLeave() {
        window.removeEventListener('keyboardWillShow', this.showListener);
        window.removeEventListener('keyboardDidHide', this.hideListener);
      }
  23. jayzyaj commented on Jul 10, 2018

    @jayzyaj

    At first at worked for me. When I first click on an input when the keyboard is shown the tabbar was hidden. After I click on another input the tabbar has showed again. So in my case the tabbar only been hided when I click on input field at first.

    Any suggestion? @dharapvj

  24. codymbeardsley commented on Jul 27, 2018

    @codymbeardsley

    Hey everyone, while it's not the same as "hiding" the tab bar, this solution worked well for me by allowing the keyboard to obscure the tab bar instead of pushing it up.

    In your main config.xml, edit the android platform to include the following:

        <platform name="android">
            ...
            <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
                <activity android:windowSoftInputMode="adjustPan" />
            </edit-config>
        </platform>
    

    What this does is modify the default value that Cordova writes to your AndroidManifest.xml to control the global keyboard input behavior for your app.

    ...and if you check AndroidManifest.xml on your next build you'll see that the default of android:windowSoftInputMode="adjustResize" is changed to "adjustPan", thus allowing the tab bar to be obscured.

  25. Motoralfa commented on Aug 3, 2018

    @Motoralfa

    @codymbeardsley Thank you so much! This solution work for me; at least for android it is a good solution. When the Keyboard is open, instead of pushing the toolbar, the keyboard just hide the footer!

    38433253_2249424885084611_5542912714352885760_n
    38404571_2249424851751281_3916148672231899136_n

  26. robroy92 commented on Aug 18, 2018

    @robroy92

    Works Perfect!
    Thank you @codymbeardsley

  27. ionitron-bot commented on Sep 17, 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.

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

Metadata

Metadata

Assignees

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