Skip to content

Commit 3a73752

Browse files
committed
fix(tabs): allow tabs to accept user-defined TabList/Tab/TabPanel
1 parent 252884b commit 3a73752

File tree

1 file changed

+21
-5
lines changed
  • packages/kit-headless/src/components/tabs

1 file changed

+21
-5
lines changed

packages/kit-headless/src/components/tabs/tabs.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import {
1313
} from '@builder.io/qwik';
1414
import { KeyCode } from '../../utils/key-code.type';
1515
import { Behavior } from './behavior.type';
16-
import { Tab, TabProps } from './tab';
17-
import { TabPanel, TabPanelProps } from './tab-panel';
16+
import { Tab as InternalTab, TabProps } from './tab';
17+
import { TabPanel as InternalTabPanel, TabPanelProps } from './tab-panel';
1818
import { tabsContextId } from './tabs-context-id';
1919
import { TabsContext } from './tabs-context.type';
20-
import { TabList } from './tabs-list';
20+
import { TabList as InternalTabList } from './tabs-list';
2121

2222
/**
2323
* TABS TODOs
@@ -56,6 +56,9 @@ export type TabsProps = {
5656
'bind:selectedTabId'?: Signal<string | undefined>;
5757
tabClass?: QwikIntrinsicElements['div']['class'];
5858
panelClass?: QwikIntrinsicElements['div']['class'];
59+
TabList?: typeof InternalTabList;
60+
Tab?: typeof InternalTab;
61+
TabPanel?: typeof InternalTabPanel;
5962
} & QwikIntrinsicElements['div'];
6063

6164
export type TabInfo = {
@@ -69,8 +72,21 @@ export type TabInfo = {
6972
// standard structure. It must take care to retain the props objects
7073
// unchanged so signals keep working
7174
export const Tabs: FunctionComponent<TabsProps> = (props) => {
72-
const { children: myChildren, tabClass, panelClass, ...rest } = props;
73-
const childrenToProcess = Array.isArray(myChildren) ? [...myChildren] : [myChildren];
75+
const {
76+
children,
77+
tabClass,
78+
panelClass,
79+
TabList: UserTabList,
80+
Tab: UserTab,
81+
TabPanel: UserTabPanel,
82+
...rest
83+
} = props;
84+
85+
const TabList = UserTabList ? UserTabList : InternalTabList;
86+
const Tab = UserTab ? UserTab : InternalTab;
87+
const TabPanel = UserTabPanel ? UserTabPanel : InternalTabPanel;
88+
89+
const childrenToProcess = Array.isArray(children) ? [...children] : [children];
7490
let tabListComponent: JSXNode | undefined;
7591
const tabComponents: JSXNode[] = [];
7692
const panelComponents: JSXNode[] = [];

0 commit comments

Comments
 (0)