UI - Search modal - fix Enter dismissing the form instead of searching (#4428)
Build and push containers / metadata (push) Canceled after 0s
Build and push containers / build-push-containers (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Canceled after 0s
ChangeDetection.io App Test / lint-code (push) Canceled after 0s
ChangeDetection.io App Test / lint-translations (push) Canceled after 0s
ChangeDetection.io App Test / lint-template-i18n (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built package works basically. (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-11 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-12 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-13 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-14 (push) Canceled after 0s

Pressing Enter in the search box closed the modal without running the search;
you had to click Search with the mouse.

Implicit form submission fires a click at the submit button, and a
keyboard-synthesised click carries detail 0 and coordinates of 0,0. The
backdrop-click handler only tested the coordinates against the dialog's
bounding box, so 0,0 read as "outside" - it closed the dialog and blanked the
input while the click was still bubbling. By the time the submit ran, `q` was
empty and `required` rejected it, so nothing was searched.

Ignore clicks with detail 0 - only a real pointer can hit the backdrop.

Verified with Chromium against a local instance: Enter now lands on
/?q=<term>, and mouse submit, backdrop click, Escape and Enter-on-empty all
still behave.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
dgtlmoon
2026-09-13 08:25:40 +02:00
committed by GitHub
co-authored by Claude Opus 5
parent 718295f30b
commit 48723a09dd
@@ -62,6 +62,15 @@
// Close modal when clicking the backdrop
searchModal.addEventListener('click', function(e) {
// Only real pointer clicks can land on the backdrop. Keyboard-synthesised clicks
// report detail 0 and coordinates of 0,0, which the geometry test below reads as
// "outside the dialog" - and implicit form submission (Enter in the input) fires
// exactly such a click at the Search button. That closed the modal and blanked
// the input mid-dispatch, so the submit that followed hit an empty `required`
// field and was rejected: Enter appeared to just dismiss the form.
if (e.detail === 0) {
return;
}
const rect = searchModal.getBoundingClientRect();
const isInDialog = (
rect.top <= e.clientY &&