oficina / docs Public

web: the keyboard's tallest-height baseline is kept per layout width

Fable's follow-up C on #181. The tallest layout height, which tells a
keyboard that shrinks the layout viewport (resizes-content) from none,
was reset whenever innerWidth changed; Mobile Safari has long reported
innerWidth as the visual viewport's width, so a pinch-zoom reset it and
the strip went. It is now keyed on documentElement.clientWidth, and the
comment says where it starts over and what it cannot tell (a turn of the
phone, a page loaded with the keyboard up, toolbars that hide on
scroll).

TestWhenTheKeyboardIsUp now zooms in while the layout viewport is
shrunk, with innerWidth reporting the visual viewport's 195px: the
strip stays. It failed before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev f8be2ddd1046ead4c12d2e4dc8835f27e79568fe parent 033f9d6
2 files changed, +21 −2
  • internal/docs/brand/phone.js +13 −2
  • internal/docs/phone_sheet_browser_test.go +8 −0
diff --git a/internal/docs/brand/phone.js b/internal/docs/brand/phone.js
index 027b0cc..eb19424 100644
--- a/internal/docs/brand/phone.js
+++ b/internal/docs/brand/phone.js
@@ -295,13 +295,24 @@
// shrinks the layout viewport itself (interactive-widget=
// resizes-content, Firefox for Android) leaves the visual viewport as
// tall as it, and shows only as the layout viewport falling short of
- // this.
+ // this. Keyed on the layout viewport's width (clientWidth), not
+ // innerWidth, which Mobile Safari long reported as the visual
+ // viewport's, so a pinch-zoom would have reset it. The edges:
+ // - A turn of the phone, or an iPad window resized, changes the
+ // width and starts over: the first height seen at the new width
+ // is the tallest until a taller one comes.
+ // - A page that loads with a keyboard already up (a reload while
+ // typing) starts from the short height, so the strip shows only
+ // once the keyboard has been down at this width.
+ // - A browser toolbar that hides on scroll changes the height by
+ // well under 150px, so it is never taken for a keyboard.
var tallest = 0, tallestAt = -1;
function place() {
var phone = !compact || compact.matches;
var focused = !!editor && editor.contains(document.activeElement);
var layout = document.documentElement.clientHeight;
- if (window.innerWidth !== tallestAt) { tallestAt = window.innerWidth; tallest = 0; }
+ var width = document.documentElement.clientWidth;
+ if (width !== tallestAt) { tallestAt = width; tallest = 0; }
if (layout > tallest) tallest = layout;
// In layout pixels (height times scale), so a pinch-zoom, which
// shrinks the visual viewport too, is not a keyboard.
diff --git a/internal/docs/phone_sheet_browser_test.go b/internal/docs/phone_sheet_browser_test.go
index 0cc51cc..7ab5e40 100644
--- a/internal/docs/phone_sheet_browser_test.go
+++ b/internal/docs/phone_sheet_browser_test.go
@@ -309,6 +309,14 @@ func TestWhenTheKeyboardIsUp(t *testing.T) {
if p := s.probe("resizes-content"); p.Quick != "strip" || !near(p.QuickTop, p.BarBottom) {
t.Errorf("the layout viewport shrunk by a keyboard: the quick bar is %q at %.1f, want the strip under the bar at %.1f", p.Quick, p.QuickTop, p.BarBottom)
}
+ // Zoomed in with that keyboard up, where innerWidth reports the
+ // visual viewport's width (as Mobile Safari's long did): the page is
+ // as wide as it was, so the strip stays (follow-up C on #181).
+ s.run("zoomed, innerWidth the visual viewport's", do(`Object.defineProperty(window, 'innerWidth', { configurable: true, get: () => 195 }); __zoom(2, 0)`), settle)
+ if p := s.probe("zoomed, resizes-content"); p.Quick != "strip" {
+ t.Errorf("zoomed in with the layout viewport shrunk by a keyboard: the quick bar is %q, want the strip still", p.Quick)
+ }
+ s.run("unzoomed again", do(`delete window.innerWidth; __zoom(1, 0)`), settle)
s.run("the keyboard down", command(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 390, Height: 844, DeviceScaleFactor: 2, Mobile: true}),
settle, do(`__keyboard(0, 0)`), settle)
if p := s.probe("the keyboard down"); p.Quick != "" {