Skip to content

Commit

Permalink
React to left-right keys and wrap list around the ends
Browse files Browse the repository at this point in the history
  • Loading branch information
bosschaert committed Sep 28, 2023
1 parent b4cb6c2 commit fedfa7a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions blocks/career-carousel/career-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ function scrollToAdjecent(spans, slideDivs, slides, next) {
return;
}

const newActive = curActive + (next ? 1 : -1);
if (newActive < 0 || newActive >= spans.length) {
return;
let newActive = curActive + (next ? 1 : -1);
if (newActive < 0) {
newActive = spans.length - 1;
} else if (newActive >= spans.length) {
newActive = 0;
}

if (slideDivs.length <= newActive) {
Expand Down Expand Up @@ -136,4 +138,17 @@ export default async function decorate(block) {

block.append(careerSlider);
block.append(navBar);

document.onkeydown = (e) => {
switch (e.keyCode) {
case 37:
la.onclick();
break;
case 39:
ra.onclick();
break;
default:
// do nothing
}
};
}

0 comments on commit fedfa7a

Please sign in to comment.