Fix arrow key scrolling and make it work on keydown instead of up

There is an issue with the new key based nav system. When control elements lose their focus, there is no good way to bring it back.
This commit is contained in:
Paul W. 2021-09-24 01:34:34 -04:00
parent 5ca5b6c41a
commit feba1d5eed
2 changed files with 4 additions and 1 deletions

View File

@ -6,5 +6,6 @@
{"title":"GitHub", "link": "https://github.com/lambdapaul"}, {"title":"GitHub", "link": "https://github.com/lambdapaul"},
{"title":"GitLab", "link": "https://gitlab.com/lambdapaul"}, {"title":"GitLab", "link": "https://gitlab.com/lambdapaul"},
{"title":"Mastodon", "link": "https://mastodon.social/@lambdapaul"}, {"title":"Mastodon", "link": "https://mastodon.social/@lambdapaul"},
{"title":"Matrix", "link": "https://matrix.to/#/@lambdapaul:matrix.org"},
{"title":"Keybase", "link": "https://keybase.io/lambdapaul"} {"title":"Keybase", "link": "https://keybase.io/lambdapaul"}
] ]

View File

@ -77,7 +77,7 @@ function fuzzyInit(pagesFileName) {
} }
); );
document.body.addEventListener("keyup", (e) => { document.body.addEventListener("keydown", (e) => {
if (e.code === "ArrowDown" || e.code === "ArrowUp") { if (e.code === "ArrowDown" || e.code === "ArrowUp") {
if (resultBlock.childNodes === null) if (resultBlock.childNodes === null)
return; return;
@ -90,6 +90,7 @@ function fuzzyInit(pagesFileName) {
let currNode = document.activeElement; let currNode = document.activeElement;
if (searchField === currNode) { if (searchField === currNode) {
e.preventDefault();
if (e.code === "ArrowDown") if (e.code === "ArrowDown")
resultNodes[0].focus(); resultNodes[0].focus();
else else
@ -100,6 +101,7 @@ function fuzzyInit(pagesFileName) {
if (Array.from(resultNodes).indexOf(currNode) < 0) if (Array.from(resultNodes).indexOf(currNode) < 0)
return; return;
e.preventDefault();
if (e.code === "ArrowDown") if (e.code === "ArrowDown")
if (currNode.nextElementSibling === null) if (currNode.nextElementSibling === null)
searchField.focus(); searchField.focus();