+1 (415) 843-4662

Keyboards and forms in Ionic apps: resize modes, autofill and validation that survives a phone

Most "this feels like a website" complaints about hybrid apps come from forms: the keyboard covers the field you are typing in, the password manager does not offer to fill, and an error message appears off-screen. All of it is fixable. This tutorial covers the settings and patterns we apply to every Ionic + Capacitor build. Examples use Ionic Angular, but the ideas apply to React and Vue.

1. Choose a keyboard resize mode on purpose

The Capacitor Keyboard plugin controls how the webview reacts when the keyboard opens.

npm install @capacitor/keyboard
npx cap sync
// capacitor.config.ts
plugins: {
  Keyboard: {
    resize: 'native',        // 'body' | 'ionic' | 'native' | 'none'
    resizeOnFullScreen: true // Android edge-to-edge
  }
}
  • native resizes the webview like a native app. It is a good default, but a fixed footer will jump up above the keyboard.
  • ionic lets Ionic scroll the focused input into view inside ion-content. It works well for long forms.
  • body resizes the body and tends to cause layout thrash. Avoid it unless you have a reason.
  • none means you handle everything yourself. Use it for chat-style UIs with a custom composer.

Test each mode on a real iOS device and a real Android device. Simulators hide timing problems.

2. Keep the focused field visible

Put forms inside ion-content and let it scroll. Avoid position: fixed wrappers around inputs. If you need a sticky submit button, use ion-footer and listen for the keyboard events to adjust it.

import { Keyboard } from '@capacitor/keyboard';

await Keyboard.addListener('keyboardWillShow', info => {
  document.documentElement.style.setProperty('--kb', `${info.keyboardHeight}px`);
});
await Keyboard.addListener('keyboardWillHide', () => {
  document.documentElement.style.setProperty('--kb', '0px');
});
ion-footer { padding-bottom: calc(var(--kb, 0px) + env(safe-area-inset-bottom)); }

Remove the listeners when the page is destroyed, or they pile up as users navigate.

3. Use the right input attributes

The keyboard type and autofill hints are plain HTML attributes. Ionic passes them through.

<ion-input type="email" inputmode="email" autocomplete="email"
           autocapitalize="off" label="Email" labelPlacement="floating"></ion-input>

<ion-input type="password" autocomplete="current-password"
           label="Password" labelPlacement="floating"></ion-input>

<ion-input inputmode="numeric" autocomplete="one-time-code"
           maxlength="6" label="Code" labelPlacement="floating"></ion-input>
  • autocomplete="one-time-code" lets iOS offer the SMS code above the keyboard. Android uses the SMS User Consent API through a separate plugin.
  • Use new-password on sign-up forms so password managers offer to generate one.
  • Set enterkeyhint="next" or "done" so the return key matches what it does.

For password manager prompts to appear in a webview, your app needs an associated domain (iOS) or Digital Asset Links (Android). Those are the same files you set up for deep links.

4. Move focus with the return key

onEnter(next: IonInput) { next.setFocus(); }
<ion-input #email enterkeyhint="next" (keyup.enter)="onEnter(pw)"></ion-input>
<ion-input #pw enterkeyhint="done" (keyup.enter)="submit()"></ion-input>

Call Keyboard.hide() after a successful submit so the keyboard does not cover the confirmation.

5. Validation that people can use

With Angular reactive forms:

form = this.fb.nonNullable.group({
  email: ['', [Validators.required, Validators.email]],
  password: ['', [Validators.required, Validators.minLength(12)]]
});
<ion-input formControlName="email" label="Email" labelPlacement="floating"
  [errorText]="'Enter a valid email address'"
  [class.ion-invalid]="f.email.invalid && f.email.touched"
  [class.ion-touched]="f.email.touched"></ion-input>

Rules we follow:

  1. Validate on blur, not on every keystroke. Do not show red text while someone is still typing.
  2. On submit, if the form is invalid, focus the first invalid control and scroll to it.
  3. Write specific messages ("Password needs at least 12 characters"), not "Invalid input".
  4. Do not rely on color alone. Error text is announced by screen readers when it is tied to the input, which Ionic's errorText does for you.
  5. Always re-validate on the server. Client validation is for convenience.

6. Edge cases worth testing

  • Rotating the device or entering split-screen with the keyboard open.
  • A hardware keyboard attached to an iPad or Android tablet.
  • Switching to a third-party keyboard such as Gboard or SwiftKey.
  • Dynamic Type and font scaling set to the maximum.
  • Pasting a code with spaces or dashes: strip them before validating.
  • The app returning from the background mid-form. Persist drafts of long forms so nothing is lost.

Checklist

  • Resize mode chosen and tested on real devices
  • No fixed-position inputs; footer accounts for keyboard height and safe area
  • type, inputmode, autocomplete and enterkeyhint set on every field
  • Return key moves focus, last field submits
  • Validation on blur, first error focused on submit
  • Keyboard listeners removed on destroy

If your Ionic app's forms feel off and you want a senior review, HybridMob's consultants can audit them in a few days.