Each tab in tabs must provide a Svelte children component (not a snippet). Panel props are passed via props. Bind activeTab to control the selection.
Setup
<script lang="ts">
import { Tabs } from '.';
</script> Default tabs
Profile panel — pass a Svelte component via each tab’s children field.
<script lang="ts">
import { Tabs } from '.';
import Panel from './Panel.svelte'; // your panel component
let activeTab = $state('profile');
const tabs = [
{ id: 'profile', title: 'Profile', children: Panel, props: { title: 'Profile' } },
{ id: 'dashboard', title: 'Dashboard', children: Panel, props: { title: 'Dashboard' } },
{ id: 'settings', title: 'Settings', children: Panel, props: { title: 'Settings' } }
];
</script>
<Tabs bind:activeTab {tabs} tabStyle="underline" /> Tab styles
tabStyle: none (default), underline, pill, full.
pill
Day panel — pass a Svelte component via each tab’s children field.
full
Day panel — pass a Svelte component via each tab’s children field.
<script lang="ts">
import { Tabs } from '.';
import Panel from './Panel.svelte';
let activeTab = $state('day');
const tabs = [
{ id: 'day', title: 'Day', children: Panel },
{ id: 'week', title: 'Week', children: Panel }
];
</script>
<Tabs bind:activeTab {tabs} tabStyle="pill" /> Closable tabs
Mark items with isClosable: true and handle onRemoveTab.
<script lang="ts">
import { Tabs } from '.';
import Panel from './Panel.svelte';
let activeTab = $state('profile');
let tabs = $state([
{ id: 'profile', title: 'Profile', isClosable: true, children: Panel },
{ id: 'settings', title: 'Settings', isClosable: true, children: Panel }
]);
</script>
<Tabs
bind:activeTab
{tabs}
tabStyle="underline"
onRemoveTab={({ tabId }) => {
tabs = tabs.filter((t) => t.id !== tabId);
if (activeTab === tabId && tabs[0]) activeTab = tabs[0].id;
}}
/> Change callback
<script lang="ts">
import { Tabs } from '.';
import Panel from './Panel.svelte';
let activeTab = $state('profile');
const tabs = [{ id: 'profile', title: 'Profile', children: Panel }];
</script>
<Tabs
bind:activeTab
{tabs}
onTabChange={(id) => console.log('active', id)}
/> Props
Tabs (TabProps)
| Prop | Type | Default | Description |
|---|---|---|---|
tabs | ITab[] | [] | Tab definitions (each needs children component) |
activeTab | string | number | 0 | Bindable active tab id |
tabStyle | 'none' | 'full' | 'pill' | 'underline' | 'none' | Visual style |
divider | boolean | true | Theme divider under the tab list |
hideTabs | boolean | true | When false, the tab list is hidden (inverted name) |
tabColor | ClassValue | 'bg-primary-500' | Active tab color utility |
tabClass | ClassValue | — | Classes on the tab list |
tabActiveClass / tabInactiveClass | ClassValue | — | Per-state tab button classes |
tabContentClass | ClassValue | — | Classes on every panel |
tabContentActiveClass / tabContentInactiveClass | ClassValue | — | Active / inactive panel classes |
onTabChange | (tabId: string \| number) => void | — | Fired when selection changes |
onTabAdd | (val: any) => void | — | Passed through to panel components |
onRemoveTab | (val: RemoveTabEvent) => void | — | Closable tab callback |
ITab
| Field | Type | Description |
|---|---|---|
id | string | number | Unique tab id |
title | string | Tab label |
children | Component | Panel component (required) |
icon | string | Optional Iconify id |
isClosable | boolean | Show close control |
props | Record<string, any> | Spread onto the panel component |
state | Record<string, any> | Optional panel state bag |
RemoveTabEvent
| Field | Type | Description |
|---|---|---|
tabId | string | number | Closed tab id |
tabData | any | Optional payload |
refresh | boolean | Optional refresh hint |