Skip to content

Commit

Permalink
Stack recognises data attributes to configure tabs (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Sep 18, 2023
1 parent bd628f3 commit 1f2fb05
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vuu-ui/packages/vuu-layout/src/stack/Stack.tsx
Expand Up @@ -21,7 +21,9 @@ const classBase = "Tabs";
const getDefaultTabIcon = () => undefined;

const getDefaultTabLabel = (component: ReactElement, tabIndex: number) =>
component.props?.title ?? `Tab ${tabIndex + 1}`;
component.props?.title ??
component.props?.["data-tab-title"] ??
`Tab ${tabIndex + 1}`;

const getChildElements = <T extends ReactElement = ReactElement>(
children: ReactNode
Expand Down Expand Up @@ -98,8 +100,11 @@ export const Stack = forwardRef(function Stack(

const renderTabs = () =>
getChildElements(children).map((child, idx) => {
const { closeable = allowCloseTab, id: childId = `${id}-${idx}` } =
child.props;
const {
closeable = allowCloseTab,
id: childId = `${id}-${idx}`,
"data-tab-location": tabLocation,
} = child.props;
return (
<Tab
ariaControls={childId}
Expand All @@ -108,6 +113,7 @@ export const Stack = forwardRef(function Stack(
id={`${childId}-tab`}
index={idx}
label={getTabLabel(child, idx)}
location={tabLocation}
closeable={closeable}
editable={allowRenameTab}
/>
Expand Down

0 comments on commit 1f2fb05

Please sign in to comment.