Skip to content

feat: useVirtualKeyboard hook, Modal bottom safe area under the keyboard - #720

Merged
blvdmitry merged 2 commits into
mainfrom
claude/eager-pascal-9nq743
Nov 21, 2026
Merged

blvdmitry merged 2 commits into
mainfrom
claude/eager-pascal-9nq743

Conversation

@blvdmitry

Copy link
Copy Markdown
Contributor

Summary

In a web app run from the iOS home screen (viewport-fit=cover), a Modal with start or end position leaves a gap between itself and the on-screen keyboard once the page is panned to its end. iOS keeps reporting the home indicator inset (34px) in env(safe-area-inset-bottom) while the keyboard covers it, and the modal keeps that inset from the bottom of the layout. bottom modals add the same inset to their bottom padding.

  • Modal subtracts the keyboard height from the bottom safe area, so the inset only applies while the keyboard is closed. --rs-modal-env-bottom is the one place that changes, so start, end and bottom positions are all covered. Contained modals are unaffected
  • useVirtualKeyboard is a new public hook returning { height }: the height of the area the on-screen keyboard covers at the bottom of the viewport. It is 0 while the keyboard is closed and when the browser resizes the layout to fit above it (Android with interactive-widget=resizes-content). Modal uses it, and apps can use it to place their own UI above the keyboard
  • @reshaped/utilities/internal gets the store behind the hook, subscribeVirtualKeyboard and getVirtualKeyboardHeight. One visualViewport listener is shared by all subscribers

How the height is measured

The keyboard height is the part of the dynamic viewport (100dvh) the visual viewport doesn't reach. window.innerHeight and the document's clientHeight can't stand in for the layout height on iOS, so 100dvh is resolved with a probe element appended for the measurement and removed right after. Two corrections on top:

  • the visual viewport height is multiplied by its scale, so pinch zoom isn't read as a keyboard
  • viewport units include a classic document scrollbar and the visual viewport doesn't, so a horizontal scrollbar would read as a 15px keyboard on desktop. Its height (100svh minus clientHeight) is taken off

Related Issue

None.

Screenshots / Recordings

None: the gap only reproduces on an iOS device with the keyboard open.

Notes for Reviewers

  • Not checked on an iOS device. The modal fix was verified end to end in a consuming app's browser tests with Chromium's safe area emulation (34px inset, stubbed visual viewport): a side modal ends 34px from the bottom with the keyboard closed and at its regular 8px offset with it open. The measurement follows the 100dvh minus visual viewport approach that app already ships on iOS
  • The classic scrollbar correction was checked by hand in Chromium with scrollbars shown (100dvh 600, clientHeight and visual viewport 585). The unit test stubs clientHeight, since headless Chromium hides scrollbars
  • Every mounted Modal subscribes, active or not. The cost is one probe measurement per visualViewport resize, shared across all of them. Say if you'd rather subscribe only while the modal is active
  • The hook returns an object rather than a number so it can grow without a breaking change. Naming (useVirtualKeyboard, height) is open
  • The hook needs a page in the docs, which live in the website repository

Tests: packages/utilities browser tests (211 passed, 5 new), story tests for useVirtualKeyboard, Modal and Overlay (25 passed), pnpm lint:js, stylelint on the modal stylesheet, pnpm build.


Generated by Claude Code

iOS keeps reporting the home indicator inset while the on-screen keyboard
covers it, so side modals ended short of the keyboard and bottom modals
kept an extra padding above it. Modal subtracts the keyboard height from
the bottom safe area, measured by the new useVirtualKeyboard hook.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMjnAukrgKSovjARByD
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Library / JS 53.38 KB (+0.34% 🔺) 1.1 s (+0.34% 🔺) 0 ms (+100% 🔺) 1.1 s
Library / CSS 24.74 KB (+0.23% 🔺) 495 ms (+0.23% 🔺) 0 ms (+100% 🔺) 495 ms
Theming / JS 7.8 KB (0%) 156 ms (0%) 69 ms (-5.53% 🔽) 225 ms
Theming with a default theme definition / JS 8.68 KB (0%) 174 ms (0%) 159 ms (+26.88% 🔺) 333 ms

@blvdmitry
blvdmitry merged commit 4f58aee into main Nov 21, 2026
11 checks passed
@blvdmitry
blvdmitry deleted the claude/eager-pascal-9nq743 branch November 21, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants