🐛 fix(search): stop modal vanishing & tapping through on mobile

This commit is contained in:
welpo 2026-04-19 19:59:27 +09:00
parent 874a1e6516
commit 8de985e290
No known key found for this signature in database
GPG key ID: C9728CF3BD2306C1
2 changed files with 6 additions and 4 deletions

View file

@ -2683,10 +2683,8 @@ window.onload = function () {
if (event.target === searchModal) { if (event.target === searchModal) {
closeModal(); closeModal();
} }
event.stopPropagation(); // Prevents tapping through the modal.
} }
searchModal.addEventListener('click', handleModalInteraction); searchModal.addEventListener('click', handleModalInteraction);
searchModal.addEventListener('touchend', handleModalInteraction, { passive: true });
// Close modal when pressing escape. // Close modal when pressing escape.
document.addEventListener('keydown', function (event) { document.addEventListener('keydown', function (event) {
@ -2709,9 +2707,13 @@ window.onload = function () {
// The index loads on mouseover/tap. // The index loads on mouseover/tap.
// Clicking/tapping the search button opens the modal. // Clicking/tapping the search button opens the modal.
// Index is preloaded on `touchstart` so it's ready by the time the synthetic
// click fires; the modal itself is opened from `click` so we don't open it
// mid-tap (which causes the follow-up synthetic click to land on the newly
// visible overlay and immediately close it again).
searchButton.addEventListener('mouseover', loadSearchIndex); searchButton.addEventListener('mouseover', loadSearchIndex);
searchButton.addEventListener('touchstart', loadSearchIndex, { passive: true });
searchButton.addEventListener('click', openSearchModal); searchButton.addEventListener('click', openSearchModal);
searchButton.addEventListener('touchstart', openSearchModal, { passive: true });
let searchIndexPromise = null; let searchIndexPromise = null;
function loadSearchIndex() { function loadSearchIndex() {

File diff suppressed because one or more lines are too long