side: Escape dismisses rail tooltips even when the side has no fold
Astra's re-review of contra-joins-ring: with Side.Fold nil, side.js returned before binding Escape dismissal, yet the rail and its tooltips are still there (explicit rail, and the width's rail below 80rem). Tooltip dismissal and its reset now bind wherever there is a side; only the folding controls and the shortcut need the fold. Tests: a Node case and nil-Fold dismissal for both rail modes in side_browser_test.go, which fail on the previous side.js and pass in Chromium and WebKit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+41
−18
side/fold.browser.mjs+5 −2side/side.js+27 −16side/side.test.mjs+9 −0
CI passed — run details
CI log
=== modcache === all modules verified === vet === CGO_ENABLED=0 go vet ./... CGO_ENABLED=0 go vet -tags browser ./... === fmt === === build === CGO_ENABLED=0 go build -buildvcs=false ./... === go-test === CGO_ENABLED=0 go test -count=1 ./... ok amadan.net/oficina/estilo.git/base 0.004s ok amadan.net/oficina/estilo.git/brand 0.003s ok amadan.net/oficina/estilo.git/busy 0.009s ok amadan.net/oficina/estilo.git/callui 0.004s ok amadan.net/oficina/estilo.git/chrome 1.041s ? amadan.net/oficina/estilo.git/cmd/oficina-notices [no test files] ok amadan.net/oficina/estilo.git/colophon 0.034s ok amadan.net/oficina/estilo.git/credits 0.005s ok amadan.net/oficina/estilo.git/credits/catalog 0.004s ok amadan.net/oficina/estilo.git/desk 0.004s ok amadan.net/oficina/estilo.git/googleimport 0.164s ok amadan.net/oficina/estilo.git/homeconnect 0.005s ok amadan.net/oficina/estilo.git/internal/lint 0.006s ? amadan.net/oficina/estilo.git/internal/tokencheck [no test files] ok amadan.net/oficina/estilo.git/menu 0.010s ok amadan.net/oficina/estilo.git/savestatus 0.121s ok amadan.net/oficina/estilo.git/side 0.146s ok amadan.net/oficina/estilo.git/sky 0.032s ok amadan.net/oficina/estilo.git/theme 0.012s
diff --git a/side/fold.browser.mjs b/side/fold.browser.mjs| index 05c484d..15ba7fb 100644 |
| --- a/side/fold.browser.mjs |
| +++ b/side/fold.browser.mjs |
| @@ -73,8 +73,11 @@ async function run(browser, origin, checks) { |
| check('shortcut: event', await page.evaluate(() => window.__keys.join()), 'prevented,prevented') |
| await page.close() |
| - // 4. Tooltips, on the explicit rail and the width's rail. |
| - for (const [label, query, width] of [['rail', '?state=rail', 1440], ['width rail', '?state=', 1000]]) { |
| + // 4. Tooltips, on the explicit rail and the width's rail, with a fold |
| + // and without one (Side.Fold nil): the rail and its tooltips are there |
| + // either way. |
| + for (const [label, query, width] of [['rail', '?state=rail', 1440], ['width rail', '?state=', 1000], |
| + ['rail, no fold', '?state=rail&fold=no', 1440], ['width rail, no fold', '?state=&fold=no', 1000]]) { |
| page = await open(query, width) |
| // Keyboard focus shows it; Escape hides it and leaves focus. |
| await page.focus('[estilo-side-item][href="/search"]') |
diff --git a/side/side.js b/side/side.js| index af79536..3e60556 100644 |
| --- a/side/side.js |
| +++ b/side/side.js |
| @@ -5,8 +5,9 @@ |
| // the same. Mapa's, copied, with focus kept and the rail's tooltips |
| // dismissable (Astra's review of contra-joins-ring). |
| // |
| -// A page with no frame, or a side drawn with no fold (Side.Fold nil), |
| -// has nothing to fold: the script binds nothing and leaves ⌘\ alone. |
| +// A page with no frame binds nothing. A side drawn with no fold |
| +// (Side.Fold nil) has nothing to fold, so ⌘\ is left alone, but its |
| +// rail's tooltips still dismiss on Escape. |
| (function () { |
| "use strict"; |
| @@ -56,10 +57,33 @@ |
| return null; |
| } |
| + // tooltips lets Escape dismiss the rail's tooltip, on the focused row |
| + // and the hovered one, leaving focus where it is. It stays dismissed |
| + // until a new hover or focus. Bound wherever there is a side, folded |
| + // or not: the width's rail has tooltips too. |
| + function tooltips(side) { |
| + document.addEventListener("keydown", function (event) { |
| + if (event.key !== "Escape" || event.defaultPrevented) return; |
| + var active = document.activeElement; |
| + side.querySelectorAll(ITEM).forEach(function (item) { |
| + if (item === active || item.matches(":hover")) item.setAttribute("data-estilo-side-tip", "off"); |
| + }); |
| + }); |
| + side.querySelectorAll(ITEM).forEach(function (item) { |
| + var again = function () { item.removeAttribute("data-estilo-side-tip"); }; |
| + item.addEventListener("pointerenter", again); |
| + item.addEventListener("focus", again); |
| + }); |
| + } |
| + |
| function start() { |
| var frame = document.querySelector("[estilo-side-frame]"); |
| var side = frame && frame.querySelector("[estilo-side]"); |
| - var form = side && side.querySelector("form[estilo-side-fold]"); |
| + if (!side) return; |
| + tooltips(side); |
| + // Folding needs the fold (Side.Fold); without it nothing folds and |
| + // the shortcut is left alone. |
| + var form = side.querySelector("form[estilo-side-fold]"); |
| if (!form) return; |
| // fold turns the side; from is the control that asked, if any. |
| @@ -98,21 +122,8 @@ |
| if ((event.metaKey || event.ctrlKey) && event.key === "\\") { |
| event.preventDefault(); |
| fold(null); |
| - } else if (event.key === "Escape" && !event.defaultPrevented) { |
| - // Escape dismisses the rail's tooltip, on the focused row and the |
| - // hovered one, and leaves focus where it is. It stays dismissed |
| - // until a new hover or focus. |
| - var active = document.activeElement; |
| - side.querySelectorAll(ITEM).forEach(function (item) { |
| - if (item === active || item.matches(":hover")) item.setAttribute("data-estilo-side-tip", "off"); |
| - }); |
| } |
| }); |
| - side.querySelectorAll(ITEM).forEach(function (item) { |
| - var again = function () { item.removeAttribute("data-estilo-side-tip"); }; |
| - item.addEventListener("pointerenter", again); |
| - item.addEventListener("focus", again); |
| - }); |
| } |
| if (document.readyState === "loading") { |
diff --git a/side/side.test.mjs b/side/side.test.mjs| index 2cc34bc..1a4ad95 100644 |
| --- a/side/side.test.mjs |
| +++ b/side/side.test.mjs |
| @@ -187,3 +187,12 @@ test("Escape dismisses the tooltip of the focused and the hovered row until a ne |
| p.search.focus(); |
| assert.equal(p.search.getAttribute("data-estilo-side-tip"), null); |
| }); |
| + |
| +test("with no fold Escape still dismisses the rail's tooltip", () => { |
| + const p = page("rail", { fold: false }); |
| + p.search.focus(); |
| + p.key({ key: "Escape" }); |
| + assert.equal(p.search.getAttribute("data-estilo-side-tip"), "off"); |
| + p.search.focus(); |
| + assert.equal(p.search.getAttribute("data-estilo-side-tip"), null); |
| +}); |