Skip to content

Commit 05ee47b

Browse files
fix: Close search when clicking outside of search area (#210)
So far, the search dialog could be closed by clicking outside of the search element, but only if no text was entered. If text was entered in the input field, it was no longer possible. This commit closes the search on click outside, independent of entered text in the search field. Co-authored-by: Lennart Rommeiss <61516567+lenderom@users.noreply.github.com>
1 parent 7d8fef9 commit 05ee47b

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

layouts/partials/stage.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@
2020
placeholder: placeholderText,
2121
}
2222
});
23+
24+
// Close search drawer on outside click
25+
document.addEventListener('mousedown', function(e) {
26+
const search = document.getElementById('search');
27+
if (!search) return;
28+
if (search.contains(e.target)) return;
29+
const closeBtn = search.querySelector('.pagefind-ui__search-clear');
30+
if (closeBtn) closeBtn.click();
31+
});
2332
});
33+
34+
// Open search on Ctrl + K or Cmd + K
2435
document.addEventListener('keydown', (e) => {
2536
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
2637
e.preventDefault();

0 commit comments

Comments
 (0)