oficina / docs Public

Docs list: the search field's clear button clears the search

Paul: the × should clear the search, not only the field. brand/list.js:
on a results page, emptying the field goes back to every document, and
the Clear search link (the scriptless way out, which the tests still
see in the markup) is hidden as redundant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 1397f5d98bfc6a7409677cbcbb9000aadc87e8fc parent 489163a
3 files changed, +17 −1
  • internal/docs/brand/list.js +15 −0
  • internal/docs/render.go +1 −1
  • internal/docs/views/list.html +1 −0

CI passed — run details

diff --git a/internal/docs/brand/list.js b/internal/docs/brand/list.js
new file mode 100644
index 0000000..3e5db20
--- /dev/null
+++ b/internal/docs/brand/list.js
@@ -0,0 +1,15 @@
+/* list.js: the document list's search field. On a results page, the
+ field's own clear button (the × a search input draws) clears the
+ search, not just the field: emptying it goes back to every document,
+ and the "Clear search" link under the results, which is the same way
+ out for a reader with no script, is taken away as redundant. */
+(function () {
+ "use strict";
+ var input = document.querySelector("[docs-search-input]");
+ if (!input || !input.value) return;
+ var clear = document.querySelector("[docs-search-clear]");
+ if (clear) clear.hidden = true;
+ input.addEventListener("input", function () {
+ if (input.value === "") location.assign("/");
+ });
+})();
diff --git a/internal/docs/render.go b/internal/docs/render.go
index f960a67..6cda77d 100644
--- a/internal/docs/render.go
+++ b/internal/docs/render.go
@@ -739,7 +739,7 @@ func vendoredStaticFS() (fs.FS, error) {
"static/estilo/sky.css": {Data: sky.CSS()},
"static/estilo/chrome.js": {Data: chrome.JS()},
}
- for _, name := range []string{"icon-32.png", "apple-touch-icon.png", "brand.css", "LICENSE.lucide", "light.css", "pointer.js"} {
+ for _, name := range []string{"icon-32.png", "apple-touch-icon.png", "brand.css", "LICENSE.lucide", "light.css", "pointer.js", "list.js"} {
body, err := brandFS.ReadFile("brand/" + name)
if err != nil {
return nil, err
diff --git a/internal/docs/views/list.html b/internal/docs/views/list.html
index 65c23dd..d2c10f6 100644
--- a/internal/docs/views/list.html
+++ b/internal/docs/views/list.html
@@ -524,4 +524,5 @@
{{end}}
</div>
{{template "docs-jumpto" .}}
+<script defer src="{{asset "static/brand/list.js"}}"></script>
{{end}}