@capacitor/keyboard
The Keyboard API provides keyboard display and visibility control, along with event tracking when the keyboard shows and hides.
Install
npm install @capacitor/keyboard
npx cap sync
Example
import { Keyboard } from '@capacitor/keyboard';
Keyboard.addListener('keyboardWillShow', info => {
console.log('keyboard will show with height:', info.keyboardHeight);
});
Keyboard.addListener('keyboardDidShow', info => {
console.log('keyboard did show with height:', info.keyboardHeight);
});
Keyboard.addListener('keyboardWillHide', () => {
console.log('keyboard will hide');
});
Keyboard.addListener('keyboardDidHide', () => {
console.log('keyboard did hide');
});
Configuration
On iOS, the keyboard can be configured with the following options:
Prop | Type | Description | Default | Since |
---|---|---|---|---|
resize |
| Configure the way the app is resized when the Keyboard appears. Only available on iOS. | native | 1.0.0 |
style | 'dark' | 'light' | Override the keyboard style if your app doesn't support dark/light theme changes. If not set, the keyboard style will depend on the device appearance. Only available on iOS. | 1.0.0 | |
resizeOnFullScreen | boolean | There is an Android bug that prevents the keyboard from resizing the WebView when the app is in full screen (i.e. if StatusBar plugin is used to overlay the status bar). This setting, if set to true, add a workaround that resizes the WebView even when the app is in full screen. Only available for Android | 1.1.0 |
Examples
In capacitor.config.json
:
{
"plugins": {
"Keyboard": {
"resize": "body",
"style": "dark",
"resizeOnFullScreen": true
}
}
}
In capacitor.config.ts
:
/// <reference types="@capacitor/keyboard" />
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
Keyboard: {
resize: "body",
style: "dark",
resizeOnFullScreen: true,
},
},
};
export default config;