Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/components/ui/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ export function Tabs<T extends string>({
}) {
const tabRefs = useRef<Map<T, HTMLButtonElement>>(new Map());

const focusTab = useCallback(
(key: T) => {
tabRefs.current.get(key)?.focus();
},
[],
);
const focusTab = useCallback((key: T) => {
tabRefs.current.get(key)?.focus();
}, []);

const handleKeyDown = useCallback(
(e: React.KeyboardEvent, currentKey: T) => {
Expand All @@ -40,10 +37,14 @@ export function Tabs<T extends string>({

switch (e.key) {
case "ArrowRight":
nextIdx = rtl ? (idx - 1 + keys.length) % keys.length : (idx + 1) % keys.length;
nextIdx = rtl
? (idx - 1 + keys.length) % keys.length
: (idx + 1) % keys.length;
break;
case "ArrowLeft":
nextIdx = rtl ? (idx + 1) % keys.length : (idx - 1 + keys.length) % keys.length;
nextIdx = rtl
? (idx + 1) % keys.length
: (idx - 1 + keys.length) % keys.length;
break;
case "Home":
nextIdx = 0;
Expand Down Expand Up @@ -79,7 +80,11 @@ export function Tabs<T extends string>({
role="tab"
id={`tab-${tab.key}`}
aria-selected={isActive}
aria-controls={`tabpanel-${tab.key}`}
// Only the ACTIVE tab's panel is rendered (ContributorDashboard
// mounts one tabpanel). aria-controls on an inactive tab pointed
// at a tabpanel id that isn't in the DOM — an ARIA reference
// error. Omit it on inactive tabs (#710).
aria-controls={isActive ? `tabpanel-${tab.key}` : undefined}
tabIndex={isActive ? 0 : -1}
onClick={() => onChange(tab.key)}
onKeyDown={(e) => handleKeyDown(e, tab.key)}
Expand Down