Capacitor Keyboard

Cap-go/capgo-skills/plugins/capacitor-features/skills/capacitor-keyboard

by Cap-go2cfb277a148832bdb1a835b01e4de323687b498bNo license72 starsListed Oct 9, 2026Updated Oct 9, 2026Repository updated today

Guide to handling keyboard in Capacitor apps including visibility detection, accessory bar, scroll behavior, and input focus. Use this skill when users have keyboard-related issues.

Instructions onlySoftware Development
AI-generated overview

Guides handling of on-screen keyboard behavior in Capacitor mobile apps, covering events, resizing, scrolling and focus.

What it does
This skill provides instructions and code examples for managing the software keyboard in Capacitor iOS and Android apps. It covers installing the @capacitor/keyboard plugin, listening to keyboard show and hide events, reading keyboard height, configuring resize modes and styles, scrolling the focused input into view, and toggling the iOS accessory bar. It also lists form best practices and a troubleshooting table for common keyboard problems.
When to use it
Use it when a Capacitor app has keyboard-related problems, such as content hidden behind the keyboard, scroll or focus issues, or a need to show, hide or observe keyboard events. It is also relevant when configuring keyboard resize behavior or the iOS accessory bar.
Requirements
Requires a Capacitor project with the @capacitor/keyboard plugin installed via npm and synced with npx cap sync. Instructions only; no scripts are shipped.

Keyboard Handling in Capacitor

Manage keyboard behavior in iOS and Android apps.

When to Use This Skill

  • User has keyboard issues
  • User needs keyboard events
  • User wants to hide keyboard
  • User has scroll issues with keyboard
  • User wants keyboard accessory bar

Quick Start

bash
npm install @capacitor/keyboardnpx cap sync

Basic Usage

typescript
import { Keyboard } from '@capacitor/keyboard';
// Show keyboardawait Keyboard.show();
// Hide keyboardawait Keyboard.hide();
// Listen for keyboard eventsKeyboard.addListener('keyboardWillShow', (info) => {  console.log('Keyboard height:', info.keyboardHeight);});
Keyboard.addListener('keyboardWillHide', () => {  console.log('Keyboard hiding');});

Configuration

typescript
// capacitor.config.tsplugins: {  Keyboard: {    resize: 'body',        // 'body' | 'ionic' | 'native' | 'none'    style: 'dark',         // 'dark' | 'light' | 'default'    resizeOnFullScreen: true,  },},

Resize Modes

ModeDescription
bodyResize body element
ionicUse Ionic's keyboard handling
nativeNative WebView resize
noneNo automatic resize

Handle Keyboard Height

typescript
import { Keyboard } from '@capacitor/keyboard';import { Capacitor } from '@capacitor/core';
if (Capacitor.isNativePlatform()) {  Keyboard.addListener('keyboardWillShow', (info) => {    document.body.style.setProperty(      '--keyboard-height',      `${info.keyboardHeight}px`    );  });
  Keyboard.addListener('keyboardWillHide', () => {    document.body.style.setProperty('--keyboard-height', '0px');  });}
css
.chat-input {  position: fixed;  bottom: calc(var(--keyboard-height, 0px) + env(safe-area-inset-bottom));  left: 0;  right: 0;}

Scroll to Input

typescript
Keyboard.addListener('keyboardWillShow', async (info) => {  const activeElement = document.activeElement as HTMLElement;
  if (activeElement) {    // Wait for keyboard animation    await new Promise((r) => setTimeout(r, 100));
    activeElement.scrollIntoView({      behavior: 'smooth',      block: 'center',    });  }});

iOS Accessory Bar

typescript
// Show/hide the toolbar above keyboardawait Keyboard.setAccessoryBarVisible({ isVisible: true });

Form Best Practices

typescript
// Prevent zoom on iOS (use font-size >= 16px)input {  font-size: 16px;}
// Handle form submissionform.addEventListener('submit', async (e) => {  e.preventDefault();  await Keyboard.hide();  // Process form});
// Move to next fieldinput.addEventListener('keypress', (e) => {  if (e.key === 'Enter') {    const nextInput = getNextInput();    if (nextInput) {      nextInput.focus();    } else {      Keyboard.hide();    }  }});

Troubleshooting

IssueSolution
Content hiddenUse resize mode
Slow animationUse keyboardWillShow
iOS zoomUse 16px font-size
Android overlapSet windowSoftInputMode

Resources

Source and attribution

Source:Cap-go/capgo-skillsinplugins/capacitor-features/skills/capacitor-keyboardat commit2cfb277

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal