oficina / memoria Public

WIP memoria: the Search button inset evenly; a ✕ that clears the box

Paul, 2026-10-31: "Button placement is off, and there should be a way to
clear search." On touch screens rastrillo made box and button the same
tap height, so the button filled the box; an even padding fixes it. The
✕ is rastrillo's [rst-search-clear] link (to / without a script); with
one it empties the box in place. Browser test, two mutations red.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 4cc01270319520b2bd17138420add7f3135570ca parent 57fe794
5 files changed, +98 −2
  • Makefile +1 −1
  • internal/memoria/static/memoria.css +10 −0
  • internal/memoria/static/search.js +23 −1
  • internal/memoria/templates/index.html +6 −0
  • internal/memoriatest/rows_browser_test.go +58 −0

CI failed — run details

diff --git a/Makefile b/Makefile
index d36dfd1..9661bb0 100644
--- a/Makefile
+++ b/Makefile
@@ -120,7 +120,7 @@ ci: vet fmt-check test migration-check
# Mac from the Playwright cache.
RASTRILLO_CHROME ?= $(firstword $(wildcard $(HOME)/Library/Caches/ms-playwright/chromium-*/chrome-mac*/Chromium.app/Contents/MacOS/Chromium))
browser:
- RASTRILLO_CHROME="$(RASTRILLO_CHROME)" CGO_ENABLED=0 go test -tags browser -count=1 -run 'OnTap|ProductionCSP|NoSidewaysScroll|SettlesADeferredBox|WholeResultIsALink|StaleAIAnswer|AnswerSlotSettles|ThumbsUp|TypeaheadAnswerCopies|AWholeRowOpens' ./internal/memoriatest/
+ RASTRILLO_CHROME="$(RASTRILLO_CHROME)" CGO_ENABLED=0 go test -tags browser -count=1 -run 'OnTap|ProductionCSP|NoSidewaysScroll|SettlesADeferredBox|WholeResultIsALink|StaleAIAnswer|AnswerSlotSettles|ThumbsUp|TypeaheadAnswerCopies|AWholeRowOpens|ClearEmptiesTheBox' ./internal/memoriatest/
.PHONY: credits
credits:
diff --git a/internal/memoria/static/memoria.css b/internal/memoria/static/memoria.css
index 1be2e76..9e443f0 100644
--- a/internal/memoria/static/memoria.css
+++ b/internal/memoria/static/memoria.css
@@ -43,6 +43,16 @@ html { scrollbar-gutter: stable; }
* input, inside the first — the double border (polish audit §B3). Only
* the spacing below it is Memoria's. */
[rst-search] { margin-bottom: 1.5rem; }
+/* The button sits inside the box with the same inset on every side
+ (Paul, 2026-10-31: "Button placement is off"). On a touch screen
+ rastrillo sets the box to the tap height with no vertical padding and
+ the button to the same tap height, so the button filled the box edge
+ to edge; a small even padding gives it room. */
+[rst-search] { padding: 0.3rem 0.3rem 0.3rem 0.75rem; }
+@media (pointer: coarse), (max-width: 40rem) {
+ [rst-search] { padding: 0.25rem 0.25rem 0.25rem 0.75rem; }
+}
+[rst-search-clear][hidden] { display: none; }
/* The front page with nothing searched (Paul, 2026-10-29): the wordmark
and the box a third of the way down, and a quiet line under it. Live
diff --git a/internal/memoria/static/search.js b/internal/memoria/static/search.js
index 797e330..75e001d 100644
--- a/internal/memoria/static/search.js
+++ b/internal/memoria/static/search.js
@@ -119,6 +119,28 @@
});
}
+ /* Clear (Paul, 2026-10-31). The link goes to the front page without a
+ script; with one it empties the box, closes the suggestions and
+ keeps the caret where it was, and it shows only while the box holds
+ something. */
+ var clearLink = form.querySelector("[rst-search-clear]");
+ function syncClear() {
+ if (clearLink) clearLink.hidden = input.value === "";
+ }
+ if (clearLink) {
+ clearLink.addEventListener("click", function (e) {
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
+ e.preventDefault();
+ input.value = "";
+ if (inflight) inflight.abort();
+ inflight = null;
+ close();
+ syncClear();
+ input.focus();
+ });
+ }
+ input.addEventListener("input", syncClear);
+
input.addEventListener("input", function () {
if (timer) clearTimeout(timer);
var q = input.value.trim();
@@ -198,7 +220,7 @@
input.addEventListener("blur", function () { close(); });
form.addEventListener("submit", function () { close(); });
// Back to a page whose box still holds text: nothing is open.
- window.addEventListener("pageshow", function () { close(); });
+ window.addEventListener("pageshow", function () { close(); syncClear(); });
})();
/* Recent searches (Paul, 2026-10-30: "a short history of the last few
diff --git a/internal/memoria/templates/index.html b/internal/memoria/templates/index.html
index e55f458..62067db 100644
--- a/internal/memoria/templates/index.html
+++ b/internal/memoria/templates/index.html
@@ -20,6 +20,12 @@
<form method="get" action="/" rst-search>
<label for="q" class="rst-sr-only">Search the team's memory</label>
<input type="search" id="q" name="q" value="{{.Query}}" placeholder="Search the team's memory…"{{if not .Searched}} autofocus{{end}}>
+ {{/* Clear (Paul, 2026-10-31): rastrillo's real link in place of the
+ browser's own ✕, which empties the box but leaves the results and
+ the ?q= standing. Without a script it goes to the front page; with
+ one, search.js empties the box and keeps the caret in it, and
+ shows the link only while there is something to clear. */}}
+ <a href="/" rst-search-clear aria-label="Clear search"{{if not .Query}} hidden{{end}}>{{icon "x"}}</a>
<button rst-btn="primary">Search</button>
</form>
<div rst-suggest-box hidden></div>
diff --git a/internal/memoriatest/rows_browser_test.go b/internal/memoriatest/rows_browser_test.go
index 974c20b..06a8e22 100644
--- a/internal/memoriatest/rows_browser_test.go
+++ b/internal/memoriatest/rows_browser_test.go
@@ -92,3 +92,61 @@ func TestAWholeRowOpens(t *testing.T) {
t.Errorf("Delete: a click on it went to %s", del)
}
}
+
+// Clear (Paul, 2026-10-31: "there should be a way to clear search"): the
+// ✕ empties the box and keeps the caret in it, without leaving the page,
+// and shows only while the box holds something.
+//
+// MUTATION-TESTED 2026-10-31, each reverted: the click handler removed
+// (the link then goes to the front page) → "left the page"; syncClear
+// not wired to typing → "while typing".
+func TestClearEmptiesTheBox(t *testing.T) {
+ rig := harness.New(t, func(origin string) http.Handler {
+ logger := slog.New(slog.NewTextHandler(io.Discard, nil))
+ d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger)
+ if err != nil {
+ t.Fatalf("db.Open: %v", err)
+ }
+ t.Cleanup(func() { d.Close() })
+ mux, _, err := memoria.AppForTest(d, origin, testDEK(t), logger)
+ if err != nil {
+ t.Fatalf("AppForTest: %v", err)
+ }
+ return mux
+ })
+ ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second)
+ defer cancel()
+ in := `input[type="search"]`
+ var value, loc string
+ var hiddenAfter, hiddenEmpty, shownTyping, focused bool
+ err := chromedp.Run(ctx,
+ chromedp.Navigate(rig.Origin+"/?q=office"),
+ chromedp.WaitVisible(`[rst-search-clear]`, chromedp.ByQuery),
+ chromedp.Click(`[rst-search-clear]`, chromedp.ByQuery),
+ chromedp.Sleep(400*time.Millisecond),
+ chromedp.Value(in, &value, chromedp.ByQuery),
+ chromedp.Location(&loc),
+ chromedp.Evaluate(`document.querySelector("[rst-search-clear]").hidden`, &hiddenAfter),
+ chromedp.Evaluate(`document.activeElement === document.querySelector('input[type="search"]')`, &focused),
+ chromedp.Navigate(rig.Origin+"/"),
+ chromedp.WaitVisible(in, chromedp.ByQuery),
+ chromedp.Evaluate(`document.querySelector("[rst-search-clear]").hidden`, &hiddenEmpty),
+ chromedp.SendKeys(in, "ab", chromedp.ByQuery),
+ chromedp.Evaluate(`!document.querySelector("[rst-search-clear]").hidden`, &shownTyping),
+ )
+ if err != nil {
+ t.Fatalf("clear: %v", err)
+ }
+ if value != "" || !hiddenAfter || !focused {
+ t.Errorf("after ✕: value %q, link hidden %v, caret in the box %v", value, hiddenAfter, focused)
+ }
+ if !strings.Contains(loc, "?q=office") {
+ t.Errorf("left the page: ✕ went to %s", loc)
+ }
+ if !hiddenEmpty {
+ t.Error("an empty box shows ✕")
+ }
+ if !shownTyping {
+ t.Error("while typing: ✕ did not appear")
+ }
+}