oficina / base Public

Show Ask as a round icon in Home's top bar on a phone

Below 600px the squeezed Ask field gives way to a 44px round glass
button with a chat-bubble line icon (labelled "Ask Base"), beside the
avatar, now also 44px. It opens the panel; with scripts off it links to
/ask. Focus returns to whichever opener the screen shows. Desktop is
unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 44df83bee514f47f80c0c07864247ce7ef668ddf parent 8f62d69
7 files changed, +50 −20
  • docs/copy-pending.md +1 −0
  • internal/browsertest/ask_test.go +1 −1
  • internal/browsertest/mobile_test.go +22 −9
  • internal/look/static/app.css +9 −3
  • internal/look/static/ask.js +14 −5
  • internal/web/templates/home.html +2 −1
  • internal/webtest/ask_test.go +1 −1
diff --git a/docs/copy-pending.md b/docs/copy-pending.md
index 7cb2447..4a5adc1 100644
--- a/docs/copy-pending.md
+++ b/docs/copy-pending.md
@@ -220,6 +220,7 @@ Review 5 (pending): "Ask Base anything", the chat with Equipo's coordinator.
|---|---|---|
| internal/web/templates/home.html | Home, the Ask field with the chat on (a link that opens the panel; "/" drawn after it) | Ask Base anything |
| internal/web/templates/partials/chat.html | Panel and /ask page, heading | Ask Base |
+| internal/web/templates/home.html | Home on a phone: the round Ask icon's accessible name (the icon replaces the field; reuses the heading) | Ask Base |
| internal/web/templates/partials/chat.html | Panel and /ask page, link to Equipo (new tab) | Open Equipo |
| internal/web/templates/partials/chat.html | Panel, close button's accessible name | Close |
| internal/web/templates/partials/chat.html | Not connected, body | Connect Equipo, and its coordinator answers you here. |
diff --git a/internal/browsertest/ask_test.go b/internal/browsertest/ask_test.go
index bc30655..bee0287 100644
--- a/internal/browsertest/ask_test.go
+++ b/internal/browsertest/ask_test.go
@@ -162,7 +162,7 @@ func TestAskPanel(t *testing.T) {
}
// On a phone the panel is the whole screen.
- drive(t, rig, chromedp.EmulateViewport(390, 844), chromedp.Click(chromedp.CSS(`a.ask`)),
+ drive(t, rig, chromedp.EmulateViewport(390, 844), chromedp.Click(chromedp.CSS(`a.ask-icon`)),
chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)))
rig.Screen("#ask-panel", "the panel on a phone")
// Once it has slid in, it covers the screen.
diff --git a/internal/browsertest/mobile_test.go b/internal/browsertest/mobile_test.go
index a918dbe..f0ddec2 100644
--- a/internal/browsertest/mobile_test.go
+++ b/internal/browsertest/mobile_test.go
@@ -76,17 +76,23 @@ func TestMobile(t *testing.T) {
noOverflow(t, rig, "sign-in")
signInByEmail(t, rig, rig.Origin, b.mail)
- // Home: the top bar on one line, no "/" hint.
+ // Home: on a phone the Ask field is a round icon button, on one line
+ // with the wordmark and the avatar.
noOverflow(t, rig, "Home")
if got := harness.Evaluate[string](rig, `(() => {
- const bar = document.querySelector(".topbar"), ask = document.querySelector("a.ask");
- const tops = [...bar.children].filter(e => getComputedStyle(e).display !== "none").map(e => Math.round(e.getBoundingClientRect().top + e.getBoundingClientRect().height / 2));
+ const bar = document.querySelector(".topbar"), icon = document.querySelector("a.ask-icon"), field = document.querySelector("a.ask");
+ const shown = [...bar.children].filter(e => getComputedStyle(e).display !== "none");
+ const mids = shown.map(e => Math.round(e.getBoundingClientRect().top + e.getBoundingClientRect().height / 2));
const problems = [];
- if (Math.max(...tops) - Math.min(...tops) > 2) problems.push("top bar wraps: " + tops.join(","));
- if (ask.getBoundingClientRect().height > 44) problems.push("Ask field is " + ask.getBoundingClientRect().height + "px tall");
- if (ask.scrollWidth > ask.clientWidth) problems.push("Ask field text overflows");
- const hint = getComputedStyle(ask, "::after");
- if (hint.content !== "none" && hint.display !== "none") problems.push("shows the / hint");
+ if (Math.max(...mids) - Math.min(...mids) > 2) problems.push("top bar wraps: " + mids.join(","));
+ if (getComputedStyle(field).display !== "none") problems.push("the Ask field shows");
+ if (!icon || getComputedStyle(icon).display === "none") return problems.concat("no Ask icon").join("; ");
+ const r = icon.getBoundingClientRect(), me = document.querySelector(".me").getBoundingClientRect();
+ if (Math.round(r.width) !== 44 || Math.round(r.height) !== 44) problems.push("icon is " + r.width + "x" + r.height);
+ if (Math.round(me.width) !== 44) problems.push("avatar is " + me.width);
+ if (icon.getAttribute("aria-label") !== "Ask Base" || icon.getAttribute("href") !== "/ask") problems.push("icon label or link");
+ const used = shown.reduce((w, e) => w + e.getBoundingClientRect().width, 0);
+ if (bar.clientWidth - used < 60) problems.push("no room to spare: " + (bar.clientWidth - used));
return problems.join("; ");
})()`); got != "" {
t.Errorf("Home's top bar on a phone: %s", got)
@@ -94,7 +100,7 @@ func TestMobile(t *testing.T) {
mobileShot(t, rig, "1-home")
// The panel before connecting.
- drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask`)),
+ drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)),
chromedp.WaitVisible(chromedp.CSS(`#ask-panel [data-when="connect"] button`)))
mobileShot(t, rig, "2-panel-connect")
@@ -138,6 +144,13 @@ func TestMobile(t *testing.T) {
t.Errorf("the panel on a phone: %s", got)
}
mobileShot(t, rig, "4-panel-conversation")
+ drive(t, rig, chromedp.KeyEvent("\u001b"),
+ chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second)))
+ // Focus goes back once the close event has run.
+ drive(t, rig, chromedp.Poll[chromedp.Void](`document.activeElement.className === "ask-icon"`, chromedp.WithPollingTimeout(3*time.Second)))
+ // Reopened from the icon, mid-conversation.
+ drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel .msg.coordinator`)))
+ mobileShot(t, rig, "4b-home-panel-open")
drive(t, rig, chromedp.KeyEvent("\u001b"))
for _, p := range []struct{ path, wait, name string }{
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index 1bbfe6e..8a8ebcc 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -179,6 +179,12 @@ a.btn { display: inline-flex; align-items: center; text-decoration: none; }
a.ask { text-decoration: none; transition: background .2s, box-shadow .2s; }
a.ask:hover { background: rgba(10,16,28,.4); box-shadow: inset 0 0 0 1px rgba(110,231,220,.45); }
a.ask::after { content: "/"; color: var(--haze); opacity: .7; }
+/* The Ask icon stands in for the field on a phone. */
+.ask-icon { display: none; flex: none; width: 44px; height: 44px; border-radius: 50%; place-items: center; margin-left: auto; color: var(--frost);
+ background: rgba(10,16,28,.25); box-shadow: inset 0 0 0 1px rgba(238,242,248,.18); transition: background .2s, box-shadow .2s; }
+.ask-icon:hover { background: rgba(10,16,28,.4); box-shadow: inset 0 0 0 1px rgba(110,231,220,.45); }
+.ask-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
+.ask-icon svg path + path { stroke-width: 2.4; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
/* Ask Base: a sheet of dark glass that slides in from the right over Home
@@ -234,10 +240,10 @@ main { min-height: 100dvh; }
.topbar { gap: 10px; padding: 6px 6px 6px 12px; }
.team { display: none; }
.ask { min-width: 0; min-height: 44px; max-width: none; padding: 0 14px; }
- a.ask { display: flex; }
- a.ask::after { content: none; }
+ a.ask { display: none; }
+ .ask-icon { display: grid; }
.ask, a.ask { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
- .me { flex: none; }
+ .me { flex: none; width: 44px; height: 44px; font-size: 14px; }
.hello { margin-top: 32px; }
.inner { padding: 10px; }
.sheet { padding: 18px 16px 20px; }
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index ece6485..bbc7de2 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -9,7 +9,10 @@ if (root) start(root);
function start(root) {
const dialog = root.tagName === "DIALOG" ? root : null;
- const opener = document.querySelector("[data-ask-open]");
+ // The Ask field, and on a phone the round Ask icon: whichever opened the
+ // panel gets focus back when it closes.
+ const openers = document.querySelectorAll("[data-ask-open]");
+ let opener = openers[0];
const thread = root.querySelector(".thread");
const empty = root.querySelector("[data-empty]");
const status = root.querySelector(".ask-status");
@@ -285,10 +288,13 @@ function start(root) {
});
field.focus();
}
- opener.addEventListener("click", (e) => {
- e.preventDefault();
- open();
- });
+ for (const o of openers) {
+ o.addEventListener("click", (e) => {
+ e.preventDefault();
+ opener = o;
+ open();
+ });
+ }
dialog.querySelector("[data-ask-close]").addEventListener("click", () => dialog.close());
// A click on the backdrop (outside the panel) closes it too.
dialog.addEventListener("click", (e) => {
@@ -300,6 +306,9 @@ function start(root) {
});
if (location.hash === "#ask") {
history.replaceState(null, "", location.pathname + location.search);
+ // Opened by the address, not a click: focus goes back to whichever
+ // opener this screen shows (the icon on a phone).
+ opener = [...openers].find((o) => o.getClientRects().length > 0) || opener;
open();
}
}
diff --git a/internal/web/templates/home.html b/internal/web/templates/home.html
index 76ffc9b..4703f58 100644
--- a/internal/web/templates/home.html
+++ b/internal/web/templates/home.html
@@ -3,7 +3,8 @@
<div class="topbar glass">
<div class="wordmark">base</div>
<div class="team">{{.Name}}</div>
-{{if .Ask}}<a class="ask" href="/ask" data-ask-open aria-haspopup="dialog" aria-controls="ask-panel">Ask Base anything</a>{{else}}<input class="ask" type="text" disabled placeholder="Ask Base anything" title="Asking Base arrives in a later slice" aria-label="Ask Base anything">{{end}}
+{{if .Ask}}<a class="ask" href="/ask" data-ask-open aria-haspopup="dialog" aria-controls="ask-panel">Ask Base anything</a>
+<a class="ask-icon" href="/ask" data-ask-open aria-haspopup="dialog" aria-controls="ask-panel" aria-label="Ask Base"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 5.5h14a1.5 1.5 0 0 1 1.5 1.5v8.5A1.5 1.5 0 0 1 19 17h-8l-4.5 3.5V17H5a1.5 1.5 0 0 1-1.5-1.5V7A1.5 1.5 0 0 1 5 5.5z"/><path d="M8.5 11.25h.01M12 11.25h.01M15.5 11.25h.01"/></svg></a>{{else}}<input class="ask" type="text" disabled placeholder="Ask Base anything" title="Asking Base arrives in a later slice" aria-label="Ask Base anything">{{end}}
<a class="me" href="/settings" aria-label="Settings">{{.Initials}}</a>
</div>
<h2 class="hello">{{.Greeting}}</h2>
diff --git a/internal/webtest/ask_test.go b/internal/webtest/ask_test.go
index 3d3cda0..e59ef53 100644
--- a/internal/webtest/ask_test.go
+++ b/internal/webtest/ask_test.go
@@ -123,7 +123,7 @@ func TestAskOffWithoutEquipo(t *testing.T) {
func TestAskFieldOpensChat(t *testing.T) {
a, _ := newAskApp(t)
home := a.get("/").Body
- for _, want := range []string{`<a class="ask" href="/ask"`, `<dialog id="ask-panel"`, `action="/ask/connect"`} {
+ for _, want := range []string{`<a class="ask" href="/ask"`, `<a class="ask-icon" href="/ask"`, `aria-label="Ask Base"`, `<dialog id="ask-panel"`, `action="/ask/connect"`} {
if !strings.Contains(home, want) {
t.Errorf("Home lacks %q:\n%s", want, home)
}