Repository navigation
feat: useVirtualKeyboard hook, Modal bottom safe area under the keyboard - #720
Merged
Merged
Conversation
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
size-limit report 📦
|
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKGZMjnAukrgKSovjARByD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In a web app run from the iOS home screen (
viewport-fit=cover), aModalwithstartorendposition 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) inenv(safe-area-inset-bottom)while the keyboard covers it, and the modal keeps that inset from the bottom of the layout.bottommodals add the same inset to their bottom padding.Modalsubtracts the keyboard height from the bottom safe area, so the inset only applies while the keyboard is closed.--rs-modal-env-bottomis the one place that changes, sostart,endandbottompositions are all covered. Contained modals are unaffecteduseVirtualKeyboardis 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 withinteractive-widget=resizes-content).Modaluses it, and apps can use it to place their own UI above the keyboard@reshaped/utilities/internalgets the store behind the hook,subscribeVirtualKeyboardandgetVirtualKeyboardHeight. OnevisualViewportlistener is shared by all subscribersHow the height is measured
The keyboard height is the part of the dynamic viewport (
100dvh) the visual viewport doesn't reach.window.innerHeightand the document'sclientHeightcan't stand in for the layout height on iOS, so100dvhis resolved with a probe element appended for the measurement and removed right after. Two corrections on top:scale, so pinch zoom isn't read as a keyboard100svhminusclientHeight) is taken offRelated Issue
None.
Screenshots / Recordings
None: the gap only reproduces on an iOS device with the keyboard open.
Notes for Reviewers
100dvhminus visual viewport approach that app already ships on iOS100dvh600,clientHeightand visual viewport 585). The unit test stubsclientHeight, since headless Chromium hides scrollbarsModalsubscribes, active or not. The cost is one probe measurement pervisualViewportresize, shared across all of them. Say if you'd rather subscribe only while the modal is activeuseVirtualKeyboard,height) is openTests:
packages/utilitiesbrowser tests (211 passed, 5 new), story tests foruseVirtualKeyboard,ModalandOverlay(25 passed),pnpm lint:js, stylelint on the modal stylesheet,pnpm build.Generated by Claude Code