Skip to content

Commit

Permalink
Wrap Tabs component with BrowserRouter for improved routing support
Browse files Browse the repository at this point in the history
  • Loading branch information
hervedombya committed Dec 13, 2024
1 parent c2c0b22 commit 398f675
Showing 1 changed file with 61 additions and 58 deletions.
119 changes: 61 additions & 58 deletions src/lib/components/tabsv2/Tabsv2.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useState,
} from 'react';
import {
BrowserRouter,
Outlet,
Route,
Routes,
Expand Down Expand Up @@ -186,65 +187,67 @@ function Tabs({
);
});
return (
<TabsContext.Provider value={true}>
<TabsContainer
style={{ containerType: 'size' }}
className={['sc-tabs', className].join(' ')}
tabLineColor={tabLineColor}
separatorColor={separatorColor}
{...rest}
>
<ScrollableContainer>
{displayScroll.start && (
<ScrollButton
ref={scrollButtonStartRef}
direction="left"
onClick={handleStartScrollClick}
/>
)}
<TabsScroller ref={tabsRef} onScroll={handleTabsScroll}>
<TabBar
onKeyDown={handleKeyDown}
ref={tabsListRef}
className="sc-tabs-bar"
role="tablist"
>
{tabItems}
</TabBar>
</TabsScroller>
{displayScroll.end && (
<ScrollButton
ref={scrollButtonEndRef}
direction="right"
onClick={handleEndScrollClick}
/>
)}
</ScrollableContainer>
<Routes>
{filteredTabsChildren.map((tab, index) => {
const path = tab.props.path.split('/').pop();
return (
<Route
key={index}
path={`/${path}`}
element={
<>
<TabContent
className="sc-tabs-item-content"
tabContentColor={tabContentColor}
withoutPadding={tab.props.withoutPadding}
>
{tab.props.children}
</TabContent>
<Outlet />
</>
}
<BrowserRouter>
<TabsContext.Provider value={true}>
<TabsContainer
style={{ containerType: 'size' }}
className={['sc-tabs', className].join(' ')}
tabLineColor={tabLineColor}
separatorColor={separatorColor}
{...rest}
>
<ScrollableContainer>
{displayScroll.start && (
<ScrollButton
ref={scrollButtonStartRef}
direction="left"
onClick={handleStartScrollClick}
/>
)}
<TabsScroller ref={tabsRef} onScroll={handleTabsScroll}>
<TabBar
onKeyDown={handleKeyDown}
ref={tabsListRef}
className="sc-tabs-bar"
role="tablist"
>
{tabItems}
</TabBar>
</TabsScroller>
{displayScroll.end && (
<ScrollButton
ref={scrollButtonEndRef}
direction="right"
onClick={handleEndScrollClick}
/>
);
})}
</Routes>
</TabsContainer>
</TabsContext.Provider>
)}
</ScrollableContainer>
<Routes>
{filteredTabsChildren.map((tab, index) => {
const path = tab.props.path.split('/').pop();
return (
<Route
key={index}
path={`/${path}`}
element={
<>
<TabContent
className="sc-tabs-item-content"
tabContentColor={tabContentColor}
withoutPadding={tab.props.withoutPadding}
>
{tab.props.children}
</TabContent>
<Outlet />
</>
}
/>
);
})}
</Routes>
</TabsContainer>
</TabsContext.Provider>
</BrowserRouter>
);
}

Expand Down

0 comments on commit 398f675

Please sign in to comment.