Skip to content

fix(ui): keep the mobile composer above the keyboard and give typing more room - #992

Merged
agegr merged 1 commit into
agegr:mainfrom
zlyuan99:fix/mobile-keyboard-composer
Sep 30, 2026
Merged

agegr merged 1 commit into
agegr:mainfrom
zlyuan99:fix/mobile-keyboard-composer

Conversation

@zlyuan99

Copy link
Copy Markdown
Contributor

Problem

On iOS Safari, focusing the composer could leave it behind the software keyboard. Users had to scroll the page down to reach it, and while they scrolled the composer jittered.

Cause, in hooks/useViewportHeight.ts:

  • WebKit updates the shrunken visualViewport.height only after the keyboard animation finishes, often without firing another resize (bugs.webkit.org 265578). An IME candidate bar (e.g. Chinese input) resizes the keyboard with no viewport event at all. The hook read the height once per event, so it kept the full-screen value.
  • When the user scrolled down to reach the composer, the hook's window.scrollTo(0, 0) pulled the page back each time, which shows up as the jitter.
  • Zoomed pages (iOS auto-zoom, pinch) were skipped entirely by the isUnscaled guard.

Even with the composer placed correctly, only a few hundred pixels remain above the keyboard on a phone. The model/controls row and the extension status line took a large share of them.

Changes

Keyboard tracking (hooks/useViewportHeight.ts)

  • Every trigger starts one non-restarting chain of re-reads (SETTLE_DELAYS_MS), so the layout settles on WebKit's final value rather than the mid-animation one.
  • composition* / input / keyup events on a focused editor also count as triggers.
  • The keyboard test compares visualViewport.height against innerHeight / scale, so zoomed pages are handled.
  • A 60px minimum (KEYBOARD_MIN_HEIGHT_PX) keeps Safari toolbar shifts from being taken for a keyboard.

More room while typing (app/globals.css, components/ChatInput.tsx)

  • While the keyboard is open, the hook sets <html data-keyboard-open>. CSS then hides .chat-input-controls and .extension-status-shelf and drops the bottom safe-area padding the keyboard already covers. Everything comes back when the keyboard closes.
  • Scope is (max-width: 640px), (pointer: coarse) and (max-height: 500px). Phone landscape is included because it has the least height; tablets keep their controls.
  • On phones, Send is icon-only (it keeps title / aria-label) and the input box padding is tighter, so the placeholder and draft keep more width.

Docs and tests

  • New AGENTS.md section on the mobile keyboard behaviour.
  • New unit tests for the zoomed, toolbar-shift and missing-scale cases.
  • MobilePwaLayout.test.mjs now asserts that every class the keyboard rules target actually exists on its component, so a rename cannot leave a rule silently dead.

Testing

  • tsc --noEmit, eslint, and npm test: all 1311 tests pass.

  • iPhone 13 emulation with a stubbed visualViewport that reproduces WebKit's order of events: resize fires first, then the height changes with no further event.

    Scenario Before After
    Keyboard opens, height settles without an event --app-viewport-height not set; composer covered composer sits right above the keyboard
    IME candidate bar adds 40px (no viewport event) covered further follows
    40px shrink (Safari toolbar) — not treated as a keyboard
    Keyboard closes — height, controls row and status shelf restored
    Phone landscape (844×390) — controls row collapses while typing
  • Checked on an iPhone in Safari. The same logic, shipped as a local runtime patch against 0.9.3, was in daily use there before this PR.

🤖 Generated with Claude Code

…more room

On iOS the composer could end up behind the software keyboard: WebKit
settles visualViewport.height only after the keyboard animation, often
without another resize event, and an IME candidate bar resizes the
keyboard with no viewport event at all. useViewportHeight read the height
once per event, so it kept the full-screen value. Scrolling down to reach
the composer then fought the hook's scrollTo(0, 0), which made the
composer jitter. Zoomed pages (iOS auto-zoom, pinch) were skipped
entirely.

- Re-read the geometry in one non-restarting settle chain after every
  trigger, and treat composition/input/keyup on a focused editor as
  triggers.
- Compare the visual viewport against innerHeight / scale, with a 60px
  minimum so Safari toolbar shifts are not taken for a keyboard.
- While the keyboard is open, mark <html data-keyboard-open> and hide the
  composer's controls row and the extension status shelf, and drop the
  bottom safe-area padding the keyboard covers. Applies to phones in
  portrait and landscape; tablets keep their controls.
- On phones, render Send as an icon-only button (with an aria-label) and
  tighten the input box padding so the draft keeps the width.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr

agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Reviewed. The iOS problem is real: WebKit settles visualViewport.height after the keyboard animation, often with no further resize (webkit 265578). Reading once per event left --app-viewport-height unset and the composer under the keyboard.

What I checked:

  • Settle chain. It can't restart, so continuous typing can't push the last re-read forward forever. Its timers are cleared on unmount, along with data-keyboard-open and the CSS variable.
  • Keyboard test. Comparing against innerHeight / scale with a 60px floor handles pinch zoom without treating Safari's toolbar shift as a keyboard. scrollTo(0, 0) is still skipped while zoomed.
  • Android. Chrome shrinks the layout viewport with the keyboard, so innerHeight follows and the attribute is never set there. The layout just stays as it is today, which is fine.
  • Layout. At 375px the icon-only Send keeps its aria-label / title, and the placeholder gets the width back. I toggled data-keyboard-open with the rule applied: the controls row and status shelf collapse, the shell padding drops to 6px, and everything comes back when the attribute is removed. The MobilePwaLayout test that every targeted class exists on its component is a nice guard against a silent rename.

One tradeoff worth knowing: while the keyboard is up on a phone, the image button and model/thinking controls are hidden too, so you dismiss the keyboard to reach them. That's a reasonable price for the height, and it's easy to revisit in CSS if people miss them.

Merged locally with current main (clean): tsc --noEmit, eslint, and the full unit suite pass (the one failure, worktree.test.mjs force removal, also fails on main in my macOS temp dir). I couldn't test on a physical iPhone. LGTM 👍


Generated by Claude Code

@agegr
agegr merged commit 390e70f into agegr:main Sep 30, 2026
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
解开 agegr#981 的 DirectoryPicker 冲突后,这一段(390e70f..f52fd84)实测 0 冲突:

- agegr#992 移动端输入框停在键盘上方并给打字更多空间
- agegr#997 限制每客户端 SSE 积压
- agegr#1001 可配置发送键(Enter / Ctrl+Enter)
- agegr#1006 从 pi 的 provider catalog 解析 discovery endpoint
- agegr#1017 空闲关闭被禁用时回收 Stop 无法解除的运行
- agegr#1016 Stop 结束输出被幸存进程持住的命令
- agegr#1015 保留用户消息里输入的换行
- agegr#1019 在 Safari / iOS 16.2 上可加载(新增 browserslist,无新依赖)
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…more room (agegr#992)

On iOS the composer could end up behind the software keyboard: WebKit
settles visualViewport.height only after the keyboard animation, often
without another resize event, and an IME candidate bar resizes the
keyboard with no viewport event at all. useViewportHeight read the height
once per event, so it kept the full-screen value. Scrolling down to reach
the composer then fought the hook's scrollTo(0, 0), which made the
composer jitter. Zoomed pages (iOS auto-zoom, pinch) were skipped
entirely.

- Re-read the geometry in one non-restarting settle chain after every
  trigger, and treat composition/input/keyup on a focused editor as
  triggers.
- Compare the visual viewport against innerHeight / scale, with a 60px
  minimum so Safari toolbar shifts are not taken for a keyboard.
- While the keyboard is open, mark <html data-keyboard-open> and hide the
  composer's controls row and the extension status shelf, and drop the
  bottom safe-area padding the keyboard covers. Applies to phones in
  portrait and landscape; tablets keep their controls.
- On phones, render Send as an icon-only button (with an aria-label) and
  tighten the input box padding so the draft keeps the width.

Co-authored-by: miller.zeng <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…more room (agegr#992)

On iOS the composer could end up behind the software keyboard: WebKit
settles visualViewport.height only after the keyboard animation, often
without another resize event, and an IME candidate bar resizes the
keyboard with no viewport event at all. useViewportHeight read the height
once per event, so it kept the full-screen value. Scrolling down to reach
the composer then fought the hook's scrollTo(0, 0), which made the
composer jitter. Zoomed pages (iOS auto-zoom, pinch) were skipped
entirely.

- Re-read the geometry in one non-restarting settle chain after every
  trigger, and treat composition/input/keyup on a focused editor as
  triggers.
- Compare the visual viewport against innerHeight / scale, with a 60px
  minimum so Safari toolbar shifts are not taken for a keyboard.
- While the keyboard is open, mark <html data-keyboard-open> and hide the
  composer's controls row and the extension status shelf, and drop the
  bottom safe-area padding the keyboard covers. Applies to phones in
  portrait and landscape; tablets keep their controls.
- On phones, render Send as an icon-only button (with an aria-label) and
  tighten the input box padding so the draft keeps the width.

Co-authored-by: miller.zeng <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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