Skip to content

Commit 42be1f3

Browse files
author
Hweinstock
committed
fix(tsc): use local variable with type guards for tabs
1 parent b5e68f8 commit 42be1f3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/components/ui/tabs/Tabs.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ export const Tabs: React.FC<TabsProps> = ({
4040
const currentIndex = tabs.findIndex((t) => t.key === effectiveActiveKey);
4141
if (key.leftArrow || input === "h") {
4242
for (let i = currentIndex - 1; i >= 0; i--) {
43-
if (!tabs[i].disabled) {
44-
onChange(tabs[i].key);
43+
const tab = tabs[i];
44+
if (tab && !tab.disabled) {
45+
onChange(tab.key);
4546
break;
4647
}
4748
}
4849
} else if (key.rightArrow || input === "l") {
4950
for (let i = currentIndex + 1; i < tabs.length; i++) {
50-
if (!tabs[i].disabled) {
51-
onChange(tabs[i].key);
51+
const tab = tabs[i];
52+
if (tab && !tab.disabled) {
53+
onChange(tab.key);
5254
break;
5355
}
5456
}
5557
} else if (input >= "1" && input <= "9") {
5658
const idx = parseInt(input, 10) - 1;
57-
if (idx < tabs.length && !tabs[idx].disabled) onChange(tabs[idx].key);
59+
const tab = tabs[idx];
60+
if (idx < tabs.length && tab && !tab.disabled) onChange(tab.key);
5861
}
5962
},
6063
{ isActive: focus },

0 commit comments

Comments
 (0)