mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 03:26:36 +00:00
52 lines
No EOL
1.3 KiB
Text
52 lines
No EOL
1.3 KiB
Text
---
|
|
components: ["Tabs", "Tab", "TabContent", "TabsSkeleton"]
|
|
---
|
|
|
|
<script>
|
|
import { Tabs, Tab, TabContent, TabsSkeleton } from "carbon-components-svelte";
|
|
import Preview from "../../components/Preview.svelte";
|
|
</script>
|
|
|
|
### Default
|
|
|
|
<Tabs>
|
|
<Tab label="Tab label 1" />
|
|
<Tab label="Tab label 2" />
|
|
<Tab label="Tab label 3" />
|
|
<div slot="content">
|
|
<TabContent>Content 1</TabContent>
|
|
<TabContent>Content 2</TabContent>
|
|
<TabContent>Content 3</TabContent>
|
|
</div>
|
|
</Tabs>
|
|
|
|
### Container type
|
|
|
|
<Tabs type="container">
|
|
<Tab label="Tab label 1" />
|
|
<Tab label="Tab label 2" />
|
|
<Tab label="Tab label 3" />
|
|
<div slot="content">
|
|
<TabContent>Content 1</TabContent>
|
|
<TabContent>Content 2</TabContent>
|
|
<TabContent>Content 3</TabContent>
|
|
</div>
|
|
</Tabs>
|
|
|
|
### Reactive example
|
|
|
|
Use the `selected` prop to bind the current tab index.
|
|
|
|
<FileSource src="/framed/Tabs/TabsReactive" />
|
|
|
|
### Re-rendering tabs
|
|
|
|
In the example below, tabs are rendered using the `#each` block. However, the Tabs component can lose track of the current index if the number of rendered tabs changes.
|
|
|
|
Use the [`#key` block](https://svelte.dev/docs#key) to dynamically update tab items or content.
|
|
|
|
<FileSource src="/framed/Tabs/TabsReactiveEach" />
|
|
|
|
### Skeleton
|
|
|
|
<TabsSkeleton count={3} /> |