From af6eeda36f89052a7a9c08a39dbe0010bdbd71e4 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 29 Jun 2023 22:46:21 +0200 Subject: Fixed a search modal bug --- themes/simple/layouts/partials/search.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/themes/simple/layouts/partials/search.html b/themes/simple/layouts/partials/search.html index 7978000..adf2cfb 100644 --- a/themes/simple/layouts/partials/search.html +++ b/themes/simple/layouts/partials/search.html @@ -52,6 +52,7 @@ // On keyboard shortcut shows search modal. let currentSearchResultsSectionIndex = -1; + const itemHoverClass = 'bg-gray-100'; document.addEventListener('keydown', function(event) { // Handles macOS CMD+k. if ((event.ctrlKey || event.metaKey) && event.key === 'k') { @@ -65,6 +66,7 @@ showSearchModal(); } + // If ESC is pressed when the input is empty close the search modal. if (event.key === 'Escape' || event.key === 'Esc') { if (searchInput.value.length == 0) { @@ -77,13 +79,15 @@ } } } else { + const listItems = searchResults.querySelectorAll('a'); + listItems.forEach(el => el.classList.remove(itemHoverClass)); + currentSearchResultsSectionIndex = -1; searchInput.focus(); } } + // Arrow UP/DOWN movement through search results. - const list = document.querySelector('.ulist'); - const itemHoverClass = 'bg-gray-100'; if (event.key === 'ArrowUp') { if (!searchResults.classList.contains('hidden')) { event.preventDefault(); -- cgit v1.2.3