Skip to content

Commit 84a5ba9

Browse files
committed
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.
1 parent 44d9f4e commit 84a5ba9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/front-end/searcher/searcher.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,11 @@ window.search = window.search || {};
369369
searchbar.select();
370370
} else if (hasFocus() && e.keyCode === DOWN_KEYCODE) {
371371
e.preventDefault();
372-
unfocusSearchbar();
373-
searchresults.firstElementChild.classList.add('focus');
372+
const first = searchresults.firstElementChild;
373+
if (first !== null) {
374+
unfocusSearchbar();
375+
first.classList.add('focus');
376+
}
374377
} else if (!hasFocus() && (e.keyCode === DOWN_KEYCODE
375378
|| e.keyCode === UP_KEYCODE
376379
|| e.keyCode === SELECT_KEYCODE)) {

0 commit comments

Comments
 (0)