steady-keyboard — for iOS Safari

Tap the field.
The page stays
in place.

When you tap a text field on an iPhone, Safari pushes the whole page up. The header disappears and the layout jumps. This library prevents that. The header and content stay in place, and the text field sits right above the keyboard.

Under 2 kB. No dependencies. Plain JavaScript, with a hook for React.

Without itSafari pushes the page up 330 px. The header is off the screen.
With steady-keyboardThe header stays. The text field sits on the keyboard.

01Try it

Open the demo in Safari on your iPhone. Tap the field and watch the header. Then open the same page without the library and compare.

Scan with your camera
keyboard.samkolabs.com/demo/ Open
keyboard.samkolabs.com/demo/?fix=off Open

02Why it happens

We measured the keyboard frame by frame on an iPhone. About 95 ms after the tap, Safari reports the new height. At 200 ms it checks whether the keyboard covers the field. If it does, it pushes the whole page up.

steady-keyboard shrinks the layout at 95 ms. When Safari checks at 200 ms, the field is already above the keyboard. There is nothing to push.

Header position 0 px −330 px With Without 0 msTap 95 msNew height, layout shrinks 200 msSafari checks the field

03Usage

Put the screen in one column and mark the bottom bar. That's it.

npm i steady-keyboard

import { useKeyboardShell, focusWithoutScroll }
  from "steady-keyboard/react";
import "steady-keyboard/shell.css";

function Chat() {
  useKeyboardShell();
  return (
    <div className="keyboard-shell">
      <header>…</header>
      <main style={{ flex: 1, overflowY: "auto" }}>…</main>
      <form data-keyboard-bar>
        <textarea onTouchEnd={focusWithoutScroll} />
      </form>
    </div>
  );
}

Without React, call installKeyboardShell() once. It returns a function that undoes everything.

04Good to know

First keyboard
The first keyboard after a page load takes about 930 ms. The library makes room in advance, using the height from last time.
Closing
The bar moves down with the keyboard. No jump.
Desktop
With a mouse, trackpad or hardware keyboard, nothing changes.
One rule
Nothing inside may use position: fixed.