From c3175321cbeaf34b12fb6e5f65a8b090f74dca21 Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Mon, 14 Apr 2025 12:11:05 -0500 Subject: [PATCH] add keyboard navigation to course tabs --- src/pages/course/[slug]/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/pages/course/[slug]/index.js b/src/pages/course/[slug]/index.js index 713bf48..c0d607f 100644 --- a/src/pages/course/[slug]/index.js +++ b/src/pages/course/[slug]/index.js @@ -381,6 +381,26 @@ const Course = () => { return items; }; + // Add keyboard navigation support for tabs + useEffect(() => { + const handleKeyDown = (e) => { + if (e.key === 'ArrowRight') { + const currentIndex = getActiveTabIndex(); + const nextIndex = (currentIndex + 1) % getTabItems().length; + toggleTab(nextIndex); + } else if (e.key === 'ArrowLeft') { + const currentIndex = getActiveTabIndex(); + const prevIndex = (currentIndex - 1 + getTabItems().length) % getTabItems().length; + toggleTab(prevIndex); + } + }; + + document.addEventListener('keydown', handleKeyDown); + return () => { + document.removeEventListener('keydown', handleKeyDown); + }; + }, [activeTab]); + // Render the QA section (empty for now) const renderQASection = () => { return (