Skip to content

Commit

Permalink
chore(Tab): allow accepting children of a single ReactElement (#2048)
Browse files Browse the repository at this point in the history
  • Loading branch information
YossiSaadi authored Apr 7, 2024
1 parent 0082caf commit 03378ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/components/Tabs/Tab/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface TabProps extends VibeComponentProps {
/**
* Tab link-name
*/
children?: string | ReactElement[];
children?: string | ReactElement | ReactElement[];
}

const Tab: FC<TabProps> = forwardRef(
Expand Down Expand Up @@ -70,11 +70,13 @@ const Tab: FC<TabProps> = forwardRef(
/>
);

const childrenArray = React.Children.toArray(children);

if (iconSide === "left") {
return [iconElement, ...children];
return [iconElement, ...childrenArray];
}

return [...children, iconElement];
return [...childrenArray, iconElement];
}
return (
<li
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ exports[`Tab renders correctly with icon on left 1`] = `
fillRule="evenodd"
/>
</svg>
T
a
b
Tab
</a>
</li>
`;
Expand All @@ -140,9 +138,7 @@ exports[`Tab renders correctly with icon on right 1`] = `
className="tabInner"
onClick={[Function]}
>
T
a
b
Tab
<svg
aria-hidden={true}
className="icon tabIcon right noFocusStyle"
Expand Down

0 comments on commit 03378ba

Please sign in to comment.