Skip to content

Commit cbcc2a7

Browse files
committed
all the things
1 parent 0ce23ef commit cbcc2a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+548
-158
lines changed

components/keyboard-nav.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { useEffect } from "react";
2+
3+
export default function KeyboardNav() {
4+
function downHandler(event) {
5+
if (!["ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight"].includes(event.key)) return
6+
7+
const slides = Array.from(document.querySelectorAll("section"));
8+
let index = Math.floor(window.scrollY / window.innerHeight)
9+
10+
if (["ArrowDown", "ArrowRight"].includes(event.key) && index < slides.length-1) {
11+
index++
12+
} else if (["ArrowUp", "ArrowLeft"].includes(event.key) && index > 0) {
13+
index--
14+
}
15+
16+
slides[index]?.scrollIntoView()
17+
18+
console.log("hwllo")
19+
20+
event.preventDefault()
21+
}
22+
23+
useEffect(() => {
24+
window.addEventListener("keydown", downHandler);
25+
26+
// Remove event listeners on cleanup
27+
// return () => {
28+
// window.removeEventListener("keydown", downHandler);
29+
// };
30+
});
31+
}

0 commit comments

Comments
 (0)