diff options
| author | Mitja Felicijan <m@mitjafelicijan.com> | 2023-06-29 22:46:21 +0200 |
|---|---|---|
| committer | Mitja Felicijan <m@mitjafelicijan.com> | 2023-06-29 22:46:21 +0200 |
| commit | af6eeda36f89052a7a9c08a39dbe0010bdbd71e4 (patch) | |
| tree | 43aa19acc1d0b6cb0e8dec0b5923e1be6257d1fc /themes/simple/layouts/partials | |
| parent | 8b0d9759340140e5033ddaf3b7ca9cdd3b1b1611 (diff) | |
| download | mitjafelicijan.com-af6eeda36f89052a7a9c08a39dbe0010bdbd71e4.tar.gz | |
Fixed a search modal bug
Diffstat (limited to 'themes/simple/layouts/partials')
| -rw-r--r-- | themes/simple/layouts/partials/search.html | 8 |
1 files 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 @@ | |||
| 52 | 52 | ||
| 53 | // On keyboard shortcut shows search modal. | 53 | // On keyboard shortcut shows search modal. |
| 54 | let currentSearchResultsSectionIndex = -1; | 54 | let currentSearchResultsSectionIndex = -1; |
| 55 | const itemHoverClass = 'bg-gray-100'; | ||
| 55 | document.addEventListener('keydown', function(event) { | 56 | document.addEventListener('keydown', function(event) { |
| 56 | // Handles macOS CMD+k. | 57 | // Handles macOS CMD+k. |
| 57 | if ((event.ctrlKey || event.metaKey) && event.key === 'k') { | 58 | if ((event.ctrlKey || event.metaKey) && event.key === 'k') { |
| @@ -65,6 +66,7 @@ | |||
| 65 | showSearchModal(); | 66 | showSearchModal(); |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 69 | |||
| 68 | // If ESC is pressed when the input is empty close the search modal. | 70 | // If ESC is pressed when the input is empty close the search modal. |
| 69 | if (event.key === 'Escape' || event.key === 'Esc') { | 71 | if (event.key === 'Escape' || event.key === 'Esc') { |
| 70 | if (searchInput.value.length == 0) { | 72 | if (searchInput.value.length == 0) { |
| @@ -77,13 +79,15 @@ | |||
| 77 | } | 79 | } |
| 78 | } | 80 | } |
| 79 | } else { | 81 | } else { |
| 82 | const listItems = searchResults.querySelectorAll('a'); | ||
| 83 | listItems.forEach(el => el.classList.remove(itemHoverClass)); | ||
| 84 | currentSearchResultsSectionIndex = -1; | ||
| 80 | searchInput.focus(); | 85 | searchInput.focus(); |
| 81 | } | 86 | } |
| 82 | } | 87 | } |
| 83 | 88 | ||
| 89 | |||
| 84 | // Arrow UP/DOWN movement through search results. | 90 | // Arrow UP/DOWN movement through search results. |
| 85 | const list = document.querySelector('.ulist'); | ||
| 86 | const itemHoverClass = 'bg-gray-100'; | ||
| 87 | if (event.key === 'ArrowUp') { | 91 | if (event.key === 'ArrowUp') { |
| 88 | if (!searchResults.classList.contains('hidden')) { | 92 | if (!searchResults.classList.contains('hidden')) { |
| 89 | event.preventDefault(); | 93 | event.preventDefault(); |
