> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Keyboard state tracking

> Get or listen for the on-screen keyboard's visibility and size, and toggle the iOS accessory view with the JavaScript Bridge.

> [!TIP]
>
> **Developer Demo**
>
> Display our demo page in your app to test during development [https://median.dev/keyboard/ ](https://median.dev/keyboard/)

## Implementation guide

Use the [Median JavaScript Bridge](https://docs.median.co/docs/javascript-bridge.md) to get or listen for the keyboard state.

### Get current keyboard state

Retrieve the current visibility status and size of the on-screen keyboard. This method accepts an optional callback function. If no callback is provided, a Promise is returned.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.keyboard.info().then(function (state) {
  console.log(state.visible); // true or false
  console.log(state.keyboardWindowSize); // { width, height }
  console.log(state.visibleWindowSize); // { width, height }
});
```

### Subscribe to keyboard state changes

Automatically listen for changes in keyboard visibility and dimensions. Define a handler function to receive updates whenever the keyboard appears, disappears, or resizes.

Median JavaScript Bridge

```javascript JavaScript theme={null}
// Called on each state change with the same object that median.keyboard.info() returns:
// visible, keyboardWindowSize { width, height }, and visibleWindowSize { width, height }
function handleKeyboardChange(state) {
  console.log(state.visible, state.keyboardWindowSize, state.visibleWindowSize);
}

median.keyboard.listen(handleKeyboardChange);

// To stop listening, pass an empty string:
// median.keyboard.listen("");
```

#### Example: hide bottom navigation when keyboard is visible

The following code hides the bottom tab bar when the keyboard appears and restores it when the keyboard is dismissed. This can be useful to preserve screen space for large forms.

Median JavaScript Bridge

```javascript JavaScript theme={null}
  // Defining a listener
  function addListener() {
    try {
      median.keyboard.listen(hideKeyboard);
      console.log("Keyboard listener added");
    } catch (error) {
      console.error("Failed to add keyboard listener", error);
    }
  }

  // Defining a callback function that will be executed on state changes
  function hideKeyboard(data) {
    if (data.visible) {
      median.tabNavigation.setTabs({ enabled: false });
    } else {
      median.tabNavigation.setTabs({ enabled: true });
    }
  }
```

### Toggle accessory view (iOS only)

On iOS devices, the software keyboard may display an accessory view containing spell check and formatting tools. Use this method to enable or disable the accessory view as needed.

Median JavaScript Bridge

```javascript JavaScript  theme={null}
median.keyboard.showAccessoryView(true); // Show accessory view
median.keyboard.showAccessoryView(false); // Hide accessory view 
```

## Demo app


## Related topics

- [Full screen](https://docs.median.co/docs/full-screen.md)
- [JavaScript Bridge overview](https://docs.median.co/docs/javascript-bridge.md)
- [Changelog archive](https://docs.median.co/docs/changelog-archive.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.