From fedfa7a23b2e2f9d50cbdbb381110993d9678a6f Mon Sep 17 00:00:00 2001 From: David Bosschaert Date: Thu, 28 Sep 2023 14:47:09 +0200 Subject: [PATCH] React to left-right keys and wrap list around the ends --- blocks/career-carousel/career-carousel.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/blocks/career-carousel/career-carousel.js b/blocks/career-carousel/career-carousel.js index ea12c0c0..c01a6fa9 100644 --- a/blocks/career-carousel/career-carousel.js +++ b/blocks/career-carousel/career-carousel.js @@ -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) { @@ -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 + } + }; }