@@ -12,6 +12,8 @@ import {
12
12
DynamicTabsExample ,
13
13
OnSelectedIndexChangeTabsExample ,
14
14
OnClickTabsExample ,
15
+ SelectedTabIdExample ,
16
+ SelectedPropExample
15
17
} from ' ./examples' ;
16
18
import { CodeExample } from ' ../../../_components/code-example/code-example' ;
17
19
import { KeyboardInteractionTable } from ' ../../../_components/keyboard-interaction-table/keyboard-interaction-table' ;
@@ -299,6 +301,75 @@ return <div>
299
301
300
302
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$ ` .
301
303
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
+
302
373
## onClick$
303
374
304
375
You can pass a custom ` onClick$ ` handler.
@@ -477,6 +548,11 @@ return <div>
477
548
type: ' boolean' ,
478
549
description: ' Set the disabled state of a specific tab' ,
479
550
},
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
+ },
480
556
]}
481
557
/>
482
558
0 commit comments