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.
This commit is contained in:
parent
44d9f4e95b
commit
84a5ba9707
1 changed files with 5 additions and 2 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue