Skip to content

Commit 1528997

Browse files
committed
Refactor and minimal API change
1 parent ab6013b commit 1528997

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Tabs.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export namespace TabsProps {
4747
}[];
4848
selectedTabId: string;
4949
onTabChange: (tabId: string) => void;
50-
children?: NonNullable<ReactNode>;
50+
children: ReactNode;
5151
};
5252
}
5353

@@ -68,8 +68,6 @@ export const Tabs = memo(
6868

6969
assert<Equals<keyof typeof rest, never>>();
7070

71-
const id = useId();
72-
7371
const getSelectedTabIndex = () =>
7472
tabs.findIndex(tab =>
7573
"content" in tab ? tab.isDefault ?? false : tab.tabId === selectedTabId
@@ -96,8 +94,17 @@ export const Tabs = memo(
9694
}
9795
});
9896

99-
const getPanelId = (tabIndex: number) => `tabpanel-${id}-${tabIndex}-panel`;
100-
const getTabId = (tabIndex: number) => `tabpanel-${id}-${tabIndex}`;
97+
const { getPanelId, getTabId } = (function useClosure() {
98+
const id = useId();
99+
100+
const getPanelId = (tabIndex: number) => `tabpanel-${id}-${tabIndex}-panel`;
101+
const getTabId = (tabIndex: number) => `tabpanel-${id}-${tabIndex}`;
102+
103+
return {
104+
getPanelId,
105+
getTabId
106+
};
107+
})();
101108

102109
return (
103110
<div className={cx(fr.cx("fr-tabs"), className)} ref={ref} style={style} {...rest}>

0 commit comments

Comments
 (0)