Skip to content

Commit cdf13c8

Browse files
committed
docs(headless/tabs): add missing examples
1 parent eb40287 commit cdf13c8

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

apps/website/src/routes/docs/headless/(components)/tabs/examples.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,42 @@ export const OnSelectedIndexChangeTabsExample = component$(() => {
234234
);
235235
});
236236

237+
export const SelectedTabIdExample = component$(() => {
238+
const selectedTabIdSig = useSignal<string | undefined>();
239+
240+
return (
241+
<PreviewCodeExample>
242+
<div q:slot="actualComponent" class="tabs-example mr-auto">
243+
<Tabs bind:selectedTabId={selectedTabIdSig}>
244+
<h3>Danish Composers</h3>
245+
<TabList>
246+
<Tab tabId="Maria">Maria Ahlefeldt</Tab>
247+
<Tab tabId="Carl">Carl Andersen</Tab>
248+
<Tab tabId="Ida">Ida Henriette da Fonseca</Tab>
249+
</TabList>
250+
<TabPanel>
251+
<p>Maria Theresia Ahlefeldt (16 January 1755 - 20 December 1810) was a ...</p>
252+
</TabPanel>
253+
<TabPanel>
254+
<p>Carl Joachim Andersen (29 April 1847 - 7 May 1909) was a ...</p>
255+
</TabPanel>
256+
<TabPanel>
257+
<p>Ida Henriette da Fonseca (July 27, 1802 - July 6, 1858) was a ...</p>
258+
</TabPanel>
259+
</Tabs>
260+
<br />
261+
<p>
262+
<strong>Selected Tab Id</strong>: {selectedTabIdSig.value}
263+
</p>
264+
</div>
265+
266+
<div q:slot="codeExample">
267+
<Slot />
268+
</div>
269+
</PreviewCodeExample>
270+
);
271+
});
272+
237273
export const OnClickTabsExample = component$(() => {
238274
const tabsClickedCountSig = useSignal(0);
239275

@@ -272,3 +308,34 @@ export const OnClickTabsExample = component$(() => {
272308
</PreviewCodeExample>
273309
);
274310
});
311+
312+
export const SelectedPropExample = component$(() => {
313+
return (
314+
<PreviewCodeExample>
315+
<div q:slot="actualComponent" class="tabs-example mr-auto">
316+
<h3>Danish Composers</h3>
317+
318+
<Tabs>
319+
<TabList>
320+
<Tab>Maria Ahlefeldt</Tab>
321+
<Tab selected>Carl Andersen</Tab>
322+
<Tab>Ida Henriette da Fonseca</Tab>
323+
</TabList>
324+
<TabPanel>
325+
<p>Maria Theresia Ahlefeldt (16 January 1755 - 20 December 1810) was a ...</p>
326+
</TabPanel>
327+
<TabPanel>
328+
<p>Carl Joachim Andersen (29 April 1847 - 7 May 1909) was a ...</p>
329+
</TabPanel>
330+
<TabPanel>
331+
<p>Ida Henriette da Fonseca (July 27, 1802 - July 6, 1858) was a ...</p>
332+
</TabPanel>
333+
</Tabs>
334+
</div>
335+
336+
<div q:slot="codeExample">
337+
<Slot />
338+
</div>
339+
</PreviewCodeExample>
340+
);
341+
});

apps/website/src/routes/docs/headless/(components)/tabs/index.mdx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
DynamicTabsExample,
1313
OnSelectedIndexChangeTabsExample,
1414
OnClickTabsExample,
15+
SelectedTabIdExample,
16+
SelectedPropExample
1517
} from './examples';
1618
import { CodeExample } from '../../../_components/code-example/code-example';
1719
import { KeyboardInteractionTable } from '../../../_components/keyboard-interaction-table/keyboard-interaction-table';
@@ -299,6 +301,75 @@ return <div>
299301

300302
You can provide a signal for the selected index with the `bind:selectedIndex={yourSignal}` and it will be used directly. This is a more efficient version of `onSelectedIndexChange$`.
301303

304+
## bind:selectedTabId
305+
306+
You can provide a signal for the selected tab id with the `bind:selectedTabId={yourSignal}`
307+
and it will be used directly.
308+
309+
💡 You can manually set the `tabId` prop on each tab to be able to select any tab by its ID.
310+
311+
312+
<SelectedTabIdExample>
313+
```tsx
314+
315+
const selectedTabIdSig = useSignal<string | undefined>();
316+
317+
return (
318+
319+
<div>
320+
<Tabs bind:selectedTabId={selectedTabIdSig}>
321+
<h3>Danish Composers</h3>
322+
<TabList>
323+
<Tab tabId="Maria">Maria Ahlefeldt</Tab>
324+
<Tab tabId="Carl">Carl Andersen</Tab>
325+
<Tab tabId="Ida">Ida Henriette da Fonseca</Tab>
326+
</TabList>
327+
<TabPanel>
328+
<p>Maria Theresia Ahlefeldt (16 January 1755 - 20 December 1810) was a ...</p>
329+
</TabPanel>
330+
<TabPanel>
331+
<p>Carl Joachim Andersen (29 April 1847 - 7 May 1909) was a ...</p>
332+
</TabPanel>
333+
<TabPanel>
334+
<p>Ida Henriette da Fonseca (July 27, 1802 - July 6, 1858) was a ...</p>
335+
</TabPanel>
336+
</Tabs>
337+
338+
<p>Selected Tab Id: {selectedTabIdSig.value}</p>
339+
</div>
340+
)
341+
```
342+
</SelectedTabIdExample>
343+
344+
345+
## Add a "selected" prop
346+
347+
You can add a "selected" prop to the Tab component to make it selected by default.
348+
349+
<SelectedPropExample>
350+
```tsx
351+
<h3>Danish Composers</h3>
352+
353+
<Tabs>
354+
<TabList>
355+
<Tab>Maria Ahlefeldt</Tab>
356+
<Tab selected>Carl Andersen</Tab>
357+
<Tab>Ida Henriette da Fonseca</Tab>
358+
</TabList>
359+
<TabPanel>
360+
<p>Maria Theresia Ahlefeldt (16 January 1755 - 20 December 1810) was a ...</p>
361+
</TabPanel>
362+
<TabPanel>
363+
<p>Carl Joachim Andersen (29 April 1847 - 7 May 1909) was a ...</p>
364+
</TabPanel>
365+
<TabPanel>
366+
<p>Ida Henriette da Fonseca (July 27, 1802 - July 6, 1858) was a ...</p>
367+
</TabPanel>
368+
</Tabs>
369+
370+
```
371+
</SelectedPropExample>
372+
302373
## onClick$
303374

304375
You can pass a custom `onClick$` handler.
@@ -477,6 +548,11 @@ return <div>
477548
type: 'boolean',
478549
description: 'Set the disabled state of a specific tab',
479550
},
551+
{
552+
name: 'tabId',
553+
type: 'string',
554+
description: 'Set the tab id, can be used with `bind:selectedTabId` to select a tab programmatically',
555+
},
480556
]}
481557
/>
482558

0 commit comments

Comments
 (0)