From bed9d5a62d443d7a71349ff6eb82c45b8da13b1d Mon Sep 17 00:00:00 2001 From: Tai Kong <294386838+aroberts957@users.noreply.github.com> Date: Mon, 31 Aug 2026 02:25:05 +0800 Subject: [PATCH] a11y: add arrow key navigation to Tabs --- frontend/src/components/ui/tabs.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/ui/tabs.tsx b/frontend/src/components/ui/tabs.tsx index 7e3f98b0..028e4600 100644 --- a/frontend/src/components/ui/tabs.tsx +++ b/frontend/src/components/ui/tabs.tsx @@ -38,6 +38,7 @@ const TabsList = React.forwardRef< >(({ className, ...props }, ref) => (
( const { value: selectedValue, onValueChange } = useTabsContext() const isSelected = value === selectedValue + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { + e.preventDefault() + const tabList = e.currentTarget.closest('[role="tablist"]') || e.currentTarget.parentElement + const tabs = Array.from(tabList?.querySelectorAll('[role="tab"]') || []) + const currentIndex = tabs.indexOf(e.currentTarget) + const nextIndex = e.key === 'ArrowLeft' + ? (currentIndex - 1 + tabs.length) % tabs.length + : (currentIndex + 1) % tabs.length + const nextTab = tabs[nextIndex] as HTMLButtonElement + nextTab?.focus() + nextTab?.click() + } + } + return (