diff --git a/src/components/ui/surface.tsx b/src/components/ui/surface.tsx index e16eba2..4a69989 100644 --- a/src/components/ui/surface.tsx +++ b/src/components/ui/surface.tsx @@ -190,23 +190,51 @@ export function SegmentedNav({ tabs, active, onChange, + idPrefix, + ariaLabel, className, }: { tabs: readonly { id: T; label: string; icon?: SurfaceIcon }[]; active: T; onChange: (id: T) => void; + idPrefix: string; + ariaLabel: string; className?: string; }) { + const activateFromKeyboard = (event: React.KeyboardEvent, currentIndex: number) => { + let nextIndex: number | null = null; + if (event.key === 'ArrowRight') nextIndex = (currentIndex + 1) % tabs.length; + if (event.key === 'ArrowLeft') nextIndex = (currentIndex - 1 + tabs.length) % tabs.length; + if (event.key === 'Home') nextIndex = 0; + if (event.key === 'End') nextIndex = tabs.length - 1; + if (nextIndex === null) return; + event.preventDefault(); + const next = tabs[nextIndex]; + onChange(next.id); + window.requestAnimationFrame(() => document.getElementById(`${idPrefix}-tab-${next.id}`)?.focus()); + }; + return (
-
- {tabs.map(({ id, label, icon: Icon }) => { +
+ {tabs.map(({ id, label, icon: Icon }, index) => { const isActive = active === id; return (