From 99a53a20294b8a389c21e777baaac0a957d0a3eb Mon Sep 17 00:00:00 2001
From: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Date: Tue, 8 Sep 2026 16:07:02 -0400
Subject: [PATCH] Close the search dialog on the first Escape
Chrome's `` consumes the first Escape to clear the
field, so closing the dialog took two presses despite the `Esc` hint.
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
---
sphinx_fuma/static/fuma.js | 5 +++++
sphinx_fuma/tests/test_theme.py | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/sphinx_fuma/static/fuma.js b/sphinx_fuma/static/fuma.js
index 0e4426a..42c4406 100644
--- a/sphinx_fuma/static/fuma.js
+++ b/sphinx_fuma/static/fuma.js
@@ -306,6 +306,11 @@
event.preventDefault();
window.location.href = active.href;
}
+ } else if (event.key === "Escape") {
+ // `` swallows the first Escape to clear itself, which
+ // would leave the dialog needing two presses despite the `Esc` hint.
+ event.preventDefault();
+ dialog.close();
}
});
diff --git a/sphinx_fuma/tests/test_theme.py b/sphinx_fuma/tests/test_theme.py
index 2c28f4e..81d19c3 100644
--- a/sphinx_fuma/tests/test_theme.py
+++ b/sphinx_fuma/tests/test_theme.py
@@ -217,6 +217,12 @@ def test_toc_scroll_spy_marks_every_visible_item_active(self, built):
assert 'entry.item.classList.add("fd-active")' in script
assert 'active[0].item.classList.add("fd-active")' not in script
+ def test_escape_closes_the_search_dialog_on_the_first_press(self, built):
+ script = (built / "_static" / "fuma.js").read_text()
+ # `` eats the first Escape to clear itself, so the
+ # dialog has to close on it explicitly.
+ assert 'event.key === "Escape"' in script
+
def test_tight_list_paragraphs_do_not_expand_item_spacing(self, built):
stylesheet = (built / "_static" / "fuma.css").read_text()
assert (".fd-prose ul.simple > li > p,\n.fd-prose ol.simple > li > p {\n margin: 0;\n}") in stylesheet