oficina / base Public

Keep More's panel on short screens; guard the rail's cut-off count

On a short screen with Home scrolled, the panel (its foot level with
More's) could rise above the top of the screen: at 1280x400 it ran
from -31px to 249px, its first links out of sight. In each cut-off
range the panel is now no taller than More's foot is below the rail's
top, so it stays on screen with the rail and scrolls inside itself.
CSS only, so it holds with scripts off.

A look test fails if Base knows more Oficina apps than app.css's
@container cut-offs cover, and says which block to add.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 2bf8b7be98468b6e666fb057b5ffa21f3ff63222 parent 9f46313
3 files changed, +100 −1
  • internal/browsertest/oficina_test.go +54 −0
  • internal/look/rail_test.go +33 −0
  • internal/look/static/app.css +13 −1
diff --git a/internal/browsertest/oficina_test.go b/internal/browsertest/oficina_test.go
index b614fa4..e34bb1a 100644
--- a/internal/browsertest/oficina_test.go
+++ b/internal/browsertest/oficina_test.go
@@ -410,3 +410,57 @@ func TestRailMoreInBrowser(t *testing.T) {
drive(t, rig, chromedp.Click(chromedp.CSS(`form.rail-collapse button`)), chromedp.WaitVisible(chromedp.CSS(`details.rail-more summary`)))
drive(t, rig, scriptsDisabled(false))
}
+
+// On a short screen, with Home scrolled so the rail is stuck at the top,
+// More's panel stays on screen: every link in it is visible or a scroll of
+// the panel away, and the keyboard's focus is always in view. With scripts
+// on and off.
+func TestRailMoreShortScreens(t *testing.T) {
+ apps := teamApps(t)
+ var b *baseApp
+ rig := newRig(t, func(origin string) http.Handler {
+ cfg := baseConfig(origin)
+ cfg.OficinaApps = apps
+ b = newBase(t, cfg)
+ return b.handler
+ })
+ drive(t, rig, chromedp.EmulateViewport(1280, 800))
+ signInByEmail(t, rig, rig.Origin, b.mail)
+ for _, off := range []bool{false, true} {
+ for _, h := range []int64{400, 500} {
+ when := fmt.Sprintf("1280x%d, scripts off %v", h, off)
+ drive(t, rig, scriptsDisabled(off), chromedp.EmulateViewport(1280, h),
+ chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")),
+ chromedp.Evaluate[chromedp.Void](`(() => { const d = document.createElement("div"); d.style.height = "2000px";
+ document.querySelector(".home-body").append(d); window.scrollTo(0, 1200); })()`),
+ chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)))
+ if got := harness.Evaluate[string](rig, `(() => {
+ const p = document.querySelector(".rail-panel").getBoundingClientRect(), vh = window.innerHeight;
+ if (window.scrollY < 1000) return "Home did not scroll";
+ if (p.top < 0 || p.bottom > vh) return "panel at " + p.top + "-" + p.bottom + " of " + vh;
+ return "";
+ })()`); got != "" {
+ t.Errorf("%s: %s", when, got)
+ }
+ // Tab from More through the panel: each link, then the switch.
+ drive(t, rig, chromedp.Focus(chromedp.CSS(`details.rail-more summary`)))
+ want := harness.Evaluate[int](rig, `[...document.querySelectorAll(".rail-panel a, .rail-panel button")].filter(e => e.checkVisibility()).length`)
+ for i := 0; i < want; i++ {
+ drive(t, rig, chromedp.KeyEvent("\t"))
+ if got := harness.Evaluate[string](rig, `(() => {
+ const a = document.activeElement, panel = document.querySelector(".rail-panel");
+ if (!panel.contains(a)) return "focus left the panel for " + a.outerHTML.slice(0, 60);
+ const r = a.getBoundingClientRect(), p = panel.getBoundingClientRect();
+ if (r.top < 0 || r.bottom > window.innerHeight || r.top < p.top - 0.5 || r.bottom > p.bottom + 0.5)
+ return a.textContent.trim() + " at " + r.top + "-" + r.bottom + ", panel " + p.top + "-" + p.bottom;
+ return "";
+ })()`); got != "" {
+ t.Errorf("%s, entry %d: %s", when, i+1, got)
+ break
+ }
+ }
+ viewportShot(t, rig, fmt.Sprintf("more-short-%d-scripts-off-%v", h, off))
+ }
+ }
+ drive(t, rig, scriptsDisabled(false))
+}
diff --git a/internal/look/rail_test.go b/internal/look/rail_test.go
new file mode 100644
index 0000000..80e2508
--- /dev/null
+++ b/internal/look/rail_test.go
@@ -0,0 +1,33 @@
+package look
+
+import (
+ "regexp"
+ "strconv"
+ "testing"
+
+ "amadan.net/carlos/base/internal/config"
+)
+
+// moreShownRE is how app.css turns More on in one of its rail cut-off
+// ranges: when an Nth app exists, the rail can't show them all.
+var moreShownRE = regexp.MustCompile(`a\.rail-app:nth-of-type\((\d+)\) ~ \.rail-more \{ display: block; \}`)
+
+// app.css decides how many Oficina apps the rail shows with one
+// @container oficina-rail block per count that fits. Past the last block
+// the rail shows every app, so it must cover every app Base knows.
+func TestRailCutOffsCoverEveryOficinaApp(t *testing.T) {
+ css, err := embedded.ReadFile("static/app.css")
+ if err != nil {
+ t.Fatal(err)
+ }
+ covered := 0
+ for _, m := range moreShownRE.FindAllStringSubmatch(string(css), -1) {
+ n, _ := strconv.Atoi(m[1])
+ covered = max(covered, n)
+ }
+ if known := len(config.OficinaIDs()); known > covered {
+ t.Errorf("Base knows %d Oficina apps but internal/look/static/app.css's @container oficina-rail cut-offs cover %d: "+
+ "add a block for each extra app, the next one (%dpx <= height < %dpx) folding app %d and on under More",
+ known, covered, 76*covered-4, 76*(covered+1)-4, covered)
+ }
+}
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index bbcdbda..a8793d0 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -169,37 +169,49 @@ button.alt[aria-busy="true"] { cursor: progress; }
/* How many apps fit: S entries need 76S - 4px of the rail's inner height.
When the apps outnumber S, the rail shows the first S - 1 and More, and
More's panel hides those S - 1. Eight apps (every one Base knows) fit
- from 604px up. */
+ from 604px up; internal/look's TestRailCutOffsCoverEveryOficinaApp fails
+ if Base learns more apps than these blocks cover.
+ The panel's foot is level with More's, so it may only be as tall as More's
+ foot is below the rail's top (76S + 5px: the rail's border and padding,
+ then S entries less a gap). The rail is always on screen, so the panel is
+ too, scrolling inside itself when its apps need more room. */
@container oficina-rail (height < 148px) {
+ .rail-panel { max-height: 81px; }
.rail.collapsed > a.rail-app:nth-of-type(n+2), .rail.collapsed > a.rail-app:nth-of-type(1):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(2) ~ .rail-more { display: block; }
}
@container oficina-rail (148px <= height < 224px) {
+ .rail-panel { max-height: 157px; }
.rail.collapsed > a.rail-app:nth-of-type(n+3), .rail.collapsed > a.rail-app:nth-of-type(2):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(3) ~ .rail-more { display: block; }
.rail-panel-app:nth-of-type(-n+1) { display: none; }
}
@container oficina-rail (224px <= height < 300px) {
+ .rail-panel { max-height: 233px; }
.rail.collapsed > a.rail-app:nth-of-type(n+4), .rail.collapsed > a.rail-app:nth-of-type(3):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(4) ~ .rail-more { display: block; }
.rail-panel-app:nth-of-type(-n+2) { display: none; }
}
@container oficina-rail (300px <= height < 376px) {
+ .rail-panel { max-height: 309px; }
.rail.collapsed > a.rail-app:nth-of-type(n+5), .rail.collapsed > a.rail-app:nth-of-type(4):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(5) ~ .rail-more { display: block; }
.rail-panel-app:nth-of-type(-n+3) { display: none; }
}
@container oficina-rail (376px <= height < 452px) {
+ .rail-panel { max-height: 385px; }
.rail.collapsed > a.rail-app:nth-of-type(n+6), .rail.collapsed > a.rail-app:nth-of-type(5):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(6) ~ .rail-more { display: block; }
.rail-panel-app:nth-of-type(-n+4) { display: none; }
}
@container oficina-rail (452px <= height < 528px) {
+ .rail-panel { max-height: 461px; }
.rail.collapsed > a.rail-app:nth-of-type(n+7), .rail.collapsed > a.rail-app:nth-of-type(6):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(7) ~ .rail-more { display: block; }
.rail-panel-app:nth-of-type(-n+5) { display: none; }
}
@container oficina-rail (528px <= height < 604px) {
+ .rail-panel { max-height: 537px; }
.rail.collapsed > a.rail-app:nth-of-type(n+8), .rail.collapsed > a.rail-app:nth-of-type(7):not(:last-of-type) { display: none; }
.rail.collapsed > a.rail-app:nth-of-type(8) ~ .rail-more { display: block; }
.rail-panel-app:nth-of-type(-n+6) { display: none; }