Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(headless): deprecate tabs shorthand api #995

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-foxes-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik-ui/headless': minor
---

We deprecated the Tabs shorthand API as it was less composable and more maintenance. We might add that API as copy/paste in the future.
15 changes: 0 additions & 15 deletions apps/website/src/routes/docs/headless/tabs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,6 @@ const CustomTabs = (props: PropsOf<typeof Tabs.Root>) => (
description:
'A signal that binds the selected tabId. This is a more efficient version of `selectedTabId` + `onSelectedTabIdChange$`',
},
{
name: 'tabClass',
type: 'string',
description: 'The class name to apply to tabs',
},
{
name: 'panelClass',
type: 'string',
description: 'The class name to apply to panels',
},
]}
/>

Expand Down Expand Up @@ -260,11 +250,6 @@ const CustomTabs = (props: PropsOf<typeof Tabs.Root>) => (

<APITable
propDescriptors={[
{
name: 'label',
type: 'element',
description: 'Shorthand for `<Tab>{label}</Tab>`',
},
{
name: 'selected',
type: 'boolean',
Expand Down
1 change: 1 addition & 0 deletions packages/kit-headless/src/components/tabs/tab-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { tabsContextId } from './tabs-context-id';

export type TabPanelProps = {
/** Optional tab contents. */
/** @deprecated This prop was used for the shorthand API that we decided to no longer support as part of the headless kit */
label?: PropsOf<'div'>['children'];
selected?: boolean;
disabled?: boolean;
Expand Down
15 changes: 0 additions & 15 deletions packages/kit-headless/src/components/tabs/tabs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,6 @@ test.describe('Disabled tabs', () => {
});
});

test.skip('Shorthand API', () => {
test(`GIVEN 3 tabs written using shorthand
WHEN clicking the middle one
THEN render the middle panel`, async ({ page }) => {
const { driver: d } = await setup(page, 'shorthand-api-tabs');

await expect(d.getAllTabs()).toHaveCount(3);

await expect(d.getTabPanel()).toContainText('Panel 3');
await d.getTab(1).click();
await expect(d.getTabPanel()).toContainText('Panel 2');
await expect(d.getTabList()).toBeVisible();
});
});

test.describe.skip('User-defined reusable TabList/Tab/TabPanel components', () => {
test(`GIVEN a user-defined TabList to Tabs
WHEN clicking the middle Tab
Expand Down
17 changes: 3 additions & 14 deletions packages/kit-headless/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ import { HTabList as InternalTabList } from './tabs-list';
* NOTE: scrolling support? or multiple lines? (probably not for headless but for tailwind / material )
* Add ability to close tabs with an ❌ icon (and keyboard support)

* TO DISCUSS
- name of the components, e.g. Tabs, Tabs.Trigger, Tabs.Panel
- selectedClassname => selectedClass
- do we keep all current props (tabId callbacks?)
- shorthand for tab: "label" or "tab"?
- the TODOs
*
*/

Expand All @@ -55,7 +49,9 @@ export type TabsProps = PropsOf<'div'> & {
onSelectedTabIdChange$?: (tabId: string) => void;
'bind:selectedIndex'?: Signal<number | undefined>;
'bind:selectedTabId'?: Signal<string | undefined>;
/** @deprecated was for the shorthand API that we decided to no longer support as part of the headless kit */
tabClass?: PropsOf<'div'>['class'];
/** @deprecated was for the shorthand API that we decided to no longer support as part of the headless kit */
panelClass?: PropsOf<'div'>['class'];

tabListComponent?: typeof InternalTabList;
Expand All @@ -76,8 +72,6 @@ export type TabInfo = {
export const HTabs: FunctionComponent<TabsProps> = (props) => {
const {
children,
tabClass,
panelClass,
tabListComponent: UserTabList,
tabComponent: UserTab,
tabPanelComponent: UserTabPanel,
Expand Down Expand Up @@ -127,16 +121,13 @@ export const HTabs: FunctionComponent<TabsProps> = (props) => {
break;
}
case TabPanel: {
const { label, selected } = child.props as TabPanelProps;
const { selected } = child.props as TabPanelProps;
// The consumer must provide a key if they change the order
const matchedTabComponent = tabComponents[panelIndex];
const tabIdFromTabMaybe =
(matchedTabComponent?.props as TabProps).tabId || matchedTabComponent?.key;
const tabId: string = tabIdFromTabMaybe || child.key || `${panelIndex}`;

if (label) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments instead of removing for deprecation

tabComponents.push((<Tab>{label}</Tab>) as JSXNode<typeof Tab>);
}
if (selected) {
selectedIndex = panelIndex;
child.props.selected = undefined;
Expand All @@ -146,7 +137,6 @@ export const HTabs: FunctionComponent<TabsProps> = (props) => {
child.key = tabId;
// Add props but don't replace the object
child.props._tabId = tabId;
child.props._extraClass = panelClass;

panelComponents.push(child);
tabInfoList.push({
Expand Down Expand Up @@ -175,7 +165,6 @@ export const HTabs: FunctionComponent<TabsProps> = (props) => {
const tabId = tabInfoList[index]?.tabId;
tab.key = tabId;
tab.props.tabId = tabId;
tab.props._extraClass = tabClass;
if (
tabInfoList[index].panelProps.disabled !== undefined &&
tab.props.disabled === undefined
Expand Down
Loading