From c06f41692f8d6173a01dc5536431e680774a1c8c Mon Sep 17 00:00:00 2001 From: MoritzWeber Date: Sat, 21 Jun 2025 21:30:50 +0200 Subject: [PATCH] fix: Close search when clicking outside of search area --- layouts/partials/stage.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/layouts/partials/stage.html b/layouts/partials/stage.html index 336a8364..01991a2b 100644 --- a/layouts/partials/stage.html +++ b/layouts/partials/stage.html @@ -20,7 +20,18 @@ placeholder: placeholderText, } }); + + // Close search drawer on outside click + document.addEventListener('mousedown', function(e) { + const search = document.getElementById('search'); + if (!search) return; + if (search.contains(e.target)) return; + const closeBtn = search.querySelector('.pagefind-ui__search-clear'); + if (closeBtn) closeBtn.click(); + }); }); + + // Open search on Ctrl + K or Cmd + K document.addEventListener('keydown', (e) => { if ((e.ctrlKey || e.metaKey) && e.key === 'k') { e.preventDefault();