Skip to content

Commit

Permalink
put TabContent div in tabs mapping, resolve ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMarcMilletScality committed Jun 25, 2024
1 parent 472f4a4 commit bf0df90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
47 changes: 25 additions & 22 deletions src/lib/components/tabsv2/Tabsv2.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @ts-nocheck
import React, { createContext, useEffect, useState, useCallback } from 'react';
import { Element, ChildrenArray } from 'react';
import React, {
createContext,
useEffect,
useState,
useCallback,
ReactElement,
} from 'react';
import {
TabBar,
ScrollableContainer,
Expand Down Expand Up @@ -32,7 +36,7 @@ type TabsProps = {
tabContentColor?: string;
separatorColor?: string;
tabHoverColor?: string;
children: ChildrenArray<Element<typeof Tab>>;
children: ReactElement<TabProps>[];
className?: string;
};
export const TabsContext = createContext<boolean>(false);
Expand All @@ -59,11 +63,12 @@ function Tabs({
const [selectedTabIndex, setSelectedTabIndex] = useState<
number | null | undefined
>(null);
const [withoutPadding, setWithoutPadding] = useState();
const queryURL = new URLSearchParams(location.search);
const filteredTabsChildren = React.Children.toArray(children).filter(
const filteredTabsChildren: ReactElement<TabProps>[] = React.Children.toArray(
children,
).filter(
(child) => React.isValidElement(child) && child.type === Tab,
);
) as ReactElement<TabProps>[];

const matchQuery = useCallback(
(query: Query): boolean => {
Expand Down Expand Up @@ -116,7 +121,6 @@ function Tabs({

if (isSelected) {
setSelectedTabIndex(index);
setWithoutPadding(child.props.withoutPadding);
hasSelectedTab = true;
}
});
Expand Down Expand Up @@ -170,18 +174,17 @@ function Tabs({
>
{icon && <TabIcon label={label}>{icon}</TabIcon>}
{isSelected ? (
<BasicText className="sc-tabs-item-title">{label}</BasicText>
<BasicText>{label}</BasicText>
) : (
<SecondaryText className="sc-tabs-item-title">{label}</SecondaryText>
)}
{textBadge && (
<EmphaseText className="sc-tabs-item-icon">{textBadge}</EmphaseText>
<SecondaryText>{label}</SecondaryText>
)}
{textBadge && <EmphaseText>{textBadge}</EmphaseText>}
</TabItem>
);
});
return (
<TabsContext.Provider value={true}>
{/*@ts-expect-error containerType is not yet a valid prop for react */}
<TabsContainer
style={{ containerType: 'size' }}
className={['sc-tabs', className].join(' ')}
Expand Down Expand Up @@ -215,17 +218,17 @@ function Tabs({
/>
)}
</ScrollableContainer>
<TabContent
className="sc-tabs-item-content"
tabContentColor={tabContentColor}
withoutPadding={withoutPadding}
>
{filteredTabsChildren.map((tab: Element<typeof Tab>, index) => (
{filteredTabsChildren.map((tab, index) => (
<TabContent
className="sc-tabs-item-content"
tabContentColor={tabContentColor}
withoutPadding={tab.props.withoutPadding}
key={index}
>
<Route
exact={tab.props.exact}
sensitive={tab.props.sensitive}
strict={tab.props.strict}
key={index}
path={
tab.props.path.startsWith('/')
? tab.props.path
Expand All @@ -239,8 +242,8 @@ function Tabs({
<></>
)}
</Route>
))}
</TabContent>
</TabContent>
))}
</TabsContainer>
</TabsContext.Provider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/tabsv2/useScrollingTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const useScrollingTabs = (selectedTabIndex: number | null | undefined) => {
scrollSelectedIntoView();
}, [scrollSelectedIntoView, selectedTabIndex]);

const handleKeyDown = (event: KeyboardEvent) => {
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
const list = tabsListRef.current;
const ownerDocument = (list && list.ownerDocument) || document;
const currentFocus = ownerDocument.activeElement;
Expand Down

0 comments on commit bf0df90

Please sign in to comment.