Skip to content

Commit

Permalink
feat: keyboard navigation completed
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Dec 6, 2023
1 parent 3f5bbed commit 38785c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/home/rendering/render-github-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ function setupKeyboardNavigation(container: HTMLDivElement) {
if (newIndex !== indexToUse) {
issues[indexToUse]?.classList.remove("selected");
issues[newIndex]?.classList.add("selected");
issues[newIndex].scrollIntoView({
behavior: "smooth",
block: "center",
});

container.classList.add("keyboard-selection");

const previewId = issues[newIndex].children[0].getAttribute("data-preview-id");
Expand All @@ -187,10 +192,14 @@ function setupKeyboardNavigation(container: HTMLDivElement) {
}
}
}
} else if (event.key === "Escape") {
disableKeyboardNavigation(event)
}
});

container.addEventListener("mouseover", (event) => {
container.addEventListener("mouseover", disableKeyboardNavigation);

function disableKeyboardNavigation(event) {
const target = event.target as HTMLElement;
container.classList.remove("keyboard-selection");
if (target && target.matches("#issues-container > div")) {
Expand All @@ -199,5 +208,5 @@ function setupKeyboardNavigation(container: HTMLDivElement) {
selectedIssue.classList.remove("selected");
}
}
});
}
}
2 changes: 1 addition & 1 deletion static/style/inverted-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
opacity: 1;
}
#issues-container.keyboard-selection > div.active {
opacity: 0.5;
opacity: 0.25;
}
#issues-container.keyboard-selection > div.active.selected {
opacity: 1;
Expand Down
2 changes: 1 addition & 1 deletion static/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
opacity: 1;
}
#issues-container.keyboard-selection > div.active {
opacity: 0.5;
opacity: 0.25;
}
#issues-container.keyboard-selection > div.active.selected {
opacity: 1;
Expand Down

0 comments on commit 38785c5

Please sign in to comment.