From 84a5ba97079027f9da188ba6d63e024c027e6a7c Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 11 May 2025 09:23:41 +0000 Subject: [PATCH] Handle `DOWN_KEYCODE` with no results If, when searching, one pressed the down arrow key when there were no results, this caused an uncaught exception and defocused the search box. Let's prevent this and keep the search box focused when pressing down in this state by checking first whether there is a result for us to focus instead. --- src/front-end/searcher/searcher.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/front-end/searcher/searcher.js b/src/front-end/searcher/searcher.js index a29883c0..d7f9f580 100644 --- a/src/front-end/searcher/searcher.js +++ b/src/front-end/searcher/searcher.js @@ -369,8 +369,11 @@ window.search = window.search || {}; searchbar.select(); } else if (hasFocus() && e.keyCode === DOWN_KEYCODE) { e.preventDefault(); - unfocusSearchbar(); - searchresults.firstElementChild.classList.add('focus'); + const first = searchresults.firstElementChild; + if (first !== null) { + unfocusSearchbar(); + first.classList.add('focus'); + } } else if (!hasFocus() && (e.keyCode === DOWN_KEYCODE || e.keyCode === UP_KEYCODE || e.keyCode === SELECT_KEYCODE)) {