Close the ⋯ menu before the panel on Escape; keep the rail on screen
Escape only closed the menu while focus was inside it: with focus moved on to Close, Escape shut the whole panel and left the menu open. The panel (or the /ask page) now handles Escape itself: an open menu closes first and focus goes back to ⋯; a later Escape closes the panel. The Oficina rail scrolled away with Home. It now sticks, is sized to the screen below the top bar, and scrolls by itself on a short screen, so every app stays reachable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+84
−28
internal/browsertest/ask_test.go+18 −0internal/browsertest/oficina_test.go+38 −0internal/look/static/app.css+9 −2internal/look/static/ask.js+19 −26
diff --git a/internal/browsertest/ask_test.go b/internal/browsertest/ask_test.go| index 52f7d59..d65a71d 100644 |
| --- a/internal/browsertest/ask_test.go |
| +++ b/internal/browsertest/ask_test.go |
| @@ -171,6 +171,24 @@ func TestAskPanel(t *testing.T) { |
| drive(t, rig, chromedp.Click(chromedp.CSS(more)), chromedp.WaitVisible(chromedp.CSS(menuLink)), |
| chromedp.Click(chromedp.CSS(`#ask-panel .thread`)), chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel details.ask-more").open`, chromedp.WithPollingTimeout(3*time.Second))) |
| + // With the menu open and focus moved on past Open Equipo to Close, the |
| + // first Escape still closes only the menu and puts focus back on ⋯. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(more)), chromedp.WaitVisible(chromedp.CSS(menuLink)), |
| + chromedp.KeyEvent("\t"), chromedp.KeyEvent("\t"), |
| + chromedp.Poll[chromedp.Void](`document.activeElement.matches("#ask-panel .close")`, chromedp.WithPollingTimeout(3*time.Second)), |
| + chromedp.KeyEvent("\u001b"), |
| + chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel details.ask-more").open`, chromedp.WithPollingTimeout(3*time.Second)), |
| + chromedp.Sleep(200*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, `(() => { |
| + const p = []; |
| + if (!document.querySelector("#ask-panel").open) p.push("the panel closed"); |
| + if (!document.activeElement.matches("#ask-panel summary")) p.push("focus is on " + document.activeElement.outerHTML.slice(0, 60)); |
| + return p.join("; "); |
| + })()`); got != "" { |
| + t.Fatalf("Escape with the menu open and focus on Close: %s", got) |
| + } |
| + |
| + // The next Escape closes the panel. |
| drive(t, rig, chromedp.KeyEvent("\u001b"), |
| chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(5*time.Second))) |
| if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "ask" { |
diff --git a/internal/browsertest/oficina_test.go b/internal/browsertest/oficina_test.go| index 59606f5..2492c89 100644 |
| --- a/internal/browsertest/oficina_test.go |
| +++ b/internal/browsertest/oficina_test.go |
| @@ -136,6 +136,44 @@ func TestOficinaRail(t *testing.T) { |
| t.Errorf("keyboard: %s", got) |
| } |
| viewportShot(t, rig, "home-desktop-focus") |
| + |
| + // The rail stays on screen when Home scrolls (a long Home stands in for |
| + // one with many apps installed). |
| + if got := harness.Evaluate[string](rig, `(() => { |
| + const tall = document.createElement("div"); |
| + tall.style.height = "2000px"; |
| + document.querySelector(".home-body").append(tall); |
| + window.scrollTo(0, 1200); |
| + const r = document.querySelector("nav.rail").getBoundingClientRect(), y = window.scrollY; |
| + tall.remove(); |
| + if (y < 1000) return "Home did not scroll: " + y; |
| + if (r.top < 0 || r.bottom > window.innerHeight || r.height < 100) return "rail at " + r.top + "-" + r.bottom + " of " + window.innerHeight; |
| + return ""; |
| + })()`); got != "" { |
| + t.Errorf("after scrolling Home: %s", got) |
| + } |
| + |
| + // On a short screen the rail scrolls by itself: the keyboard reaches the |
| + // last app and it is on screen, inside the rail. |
| + drive(t, rig, chromedp.EmulateViewport(1280, 600), chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello"))) |
| + keys := []chromedp.Action[chromedp.Void]{} |
| + for range 3 + len(apps) - 1 { |
| + keys = append(keys, chromedp.KeyEvent("\t")) |
| + } |
| + drive(t, rig, keys...) |
| + if got := harness.Evaluate[string](rig, `(() => { |
| + const a = document.activeElement, rail = document.querySelector("nav.rail"); |
| + if (!a.matches("nav.rail a:last-child")) return "focus is on " + a.outerHTML.slice(0, 80); |
| + const r = a.getBoundingClientRect(), rr = rail.getBoundingClientRect(); |
| + if (r.top < 0 || r.bottom > window.innerHeight) return "last app at " + r.top + "-" + r.bottom + " of " + window.innerHeight; |
| + if (r.top < rr.top - 0.5 || r.bottom > rr.bottom + 0.5) return "last app outside the rail: " + r.top + "-" + r.bottom + ", rail " + rr.top + "-" + rr.bottom; |
| + if (rr.bottom > window.innerHeight + 0.5 && window.scrollY === 0) return "rail runs off the screen at " + rr.bottom; |
| + return ""; |
| + })()`); got != "" { |
| + t.Errorf("at 1280x600: %s", got) |
| + } |
| + viewportShot(t, rig, "home-desktop-short") |
| + drive(t, rig, chromedp.EmulateViewport(1280, 800)) |
| drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello"))) |
| viewportShot(t, rig, "home-desktop") |
| } |
diff --git a/internal/look/static/app.css b/internal/look/static/app.css| index 1f5e7a5..d99faac 100644 |
| --- a/internal/look/static/app.css |
| +++ b/internal/look/static/app.css |
| @@ -122,9 +122,16 @@ button.alt[aria-busy="true"] { cursor: progress; } |
| .home-cols { flex: 1; display: flex; gap: 22px; } |
| .home-body { flex: 1; min-width: 0; display: flex; flex-direction: column; } |
| /* The Oficina rail: a slim column of glass down the left, under the top bar. |
| - Each app is its icon with its name under it, a link that opens it in a new tab. */ |
| + Each app is its icon with its name under it, a link that opens it in a new tab. |
| + It sticks when Home scrolls, and on a short screen scrolls by itself. Its |
| + height fits the screen below the top bar (117px: Home's padding, the top bar |
| + and the gap under it), so every entry is on screen or a scroll away in it. */ |
| .rail { flex: none; width: 80px; margin-top: 16px; padding: 8px 6px; border-radius: 18px; |
| - display: flex; flex-direction: column; gap: 4px; } |
| + display: flex; flex-direction: column; gap: 4px; |
| + position: sticky; top: 16px; align-self: flex-start; |
| + height: max(160px, calc(100dvh - 117px)); |
| + overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; } |
| +.rail-app { flex: none; } |
| .rail-app { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 9px 2px 8px; border-radius: 12px; |
| color: var(--frost); text-decoration: none; font-size: 12px; font-weight: 500; line-height: 1.2; transition: background .2s; } |
| .rail-app img { width: 36px; height: 36px; display: block; } |
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js| index 4172dd2..4398518 100644 |
| --- a/internal/look/static/ask.js |
| +++ b/internal/look/static/ask.js |
| @@ -260,42 +260,35 @@ function start(root) { |
| setTurn(out.turn); |
| }); |
| - // The ⋯ menu: Escape (without closing the panel) and a click elsewhere |
| - // close it, and focus goes back to ⋯. Without scripts it is a plain |
| - // <details>. |
| - let menuEscape = false; |
| - for (const menu of root.querySelectorAll("details.ask-more")) { |
| + // The ⋯ menu: Escape and a click elsewhere close it, and focus goes back |
| + // to ⋯. Without scripts it is a plain <details>. |
| + const menus = [...root.querySelectorAll("details.ask-more")]; |
| + for (const menu of menus) { |
| const button = menu.querySelector("summary"); |
| - const shut = () => { |
| - if (!menu.open) return; |
| - menu.open = false; |
| - button.focus(); |
| - }; |
| - menu.addEventListener("keydown", (e) => { |
| - if (e.key !== "Escape" || !menu.open) return; |
| - // In the panel the same key asks the dialog to close; its cancel |
| - // handler below sees this flag and keeps it open. |
| - menuEscape = !!dialog; |
| - setTimeout(() => { menuEscape = false; }, 100); |
| - if (!dialog) e.preventDefault(); |
| - shut(); |
| - }); |
| document.addEventListener("click", (e) => { |
| - if (menu.open && !menu.contains(e.target)) shut(); |
| + if (menu.open && !menu.contains(e.target)) { |
| + menu.open = false; |
| + button.focus(); |
| + } |
| }); |
| menu.querySelector(".ask-menu a").addEventListener("click", () => { menu.open = false; }); |
| } |
| + // Escape anywhere in the panel (or the /ask page) closes an open menu |
| + // first, wherever focus is; only a later Escape closes the panel. |
| + // Cancelling the keydown stops the dialog's close request. |
| + (dialog || document).addEventListener("keydown", (e) => { |
| + if (e.key !== "Escape") return; |
| + const menu = menus.find((m) => m.open); |
| + if (!menu) return; |
| + e.preventDefault(); |
| + menu.open = false; |
| + menu.querySelector("summary").focus(); |
| + }, true); |
| if (!dialog) { |
| load(); |
| return; |
| } |
| - // Escape that closed the ⋯ menu leaves the panel open. |
| - dialog.addEventListener("cancel", (e) => { |
| - if (menuEscape) e.preventDefault(); |
| - menuEscape = false; |
| - }); |
| - |
| // On a phone the sheet follows the visual viewport, which shrinks when the |
| // keyboard opens: the composer stays above it. |
| const vv = window.visualViewport; |