fix(dashboard-v2): fix tabs default tab behavior

This commit is contained in:
Michał Leszczyk 2022-03-07 12:09:51 +01:00
parent aa6db3d115
commit badc487018
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
1 changed files with 5 additions and 1 deletions

View File

@ -34,7 +34,11 @@ const Body = styled.div.attrs({ className: "grow min-h-0" })``;
export const Tabs = ({ defaultTab, children, variant }) => {
const getTabId = usePrefixedTabIds();
const { tabs, panels, tabsRefs } = useTabsChildren(children, getTabId);
const defaultTabId = useMemo(() => getTabId(defaultTab || tabs[0].props.id), [getTabId, defaultTab, tabs]);
const defaultTabId = useMemo(() => {
const requestedTabIsPresent = tabs.find(({ props }) => props.id === defaultTab);
return getTabId(requestedTabIsPresent ? defaultTab : tabs[0].props.id);
}, [getTabId, defaultTab, tabs]);
const [activeTabId, setActiveTabId] = useState(defaultTabId);
const [activeTabRef, setActiveTabRef] = useState(tabsRefs[activeTabId]);
const isActive = (id) => id === activeTabId;