Tabs
Panels of one view behind a segmented list.
Three drafts are in review. The next one is due on Friday.
Sam left two comments on the cover layout this morning.
Reviews close automatically after seven days.
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import TabsExample from './TabsExample.svelte';
</script>
<TabsExample disabled={false} />
<script lang="ts">
import { Tabs } from 'portal-bits';
let { disabled = false }: { disabled?: boolean } = $props();
let current = $state('overview');
</script>
{#snippet overview()}
<p>Three drafts are in review. The next one is due on Friday.</p>
{/snippet}
{#snippet activity()}
<p>Sam left two comments on the cover layout this morning.</p>
{/snippet}
{#snippet settings()}
<p>Reviews close automatically after seven days.</p>
{/snippet}
<div class="frame">
<Tabs
label="Project sections"
bind:value={current}
items={[
{ value: 'overview', label: 'Overview', content: overview },
{ value: 'activity', label: 'Activity', content: activity },
{ value: 'settings', label: 'Settings', content: settings, disabled },
]}
/>
</div>
<style>
.frame {
width: 420px;
max-width: 100%;
}
p {
margin: 0;
color: var(--portal-muted);
}
</style>
API reference
These tables list the props and snippets that Tabs declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | Names the tab list. |
items | TabItem[] | None | Yes | One-way | Tabs as `{ value, label, content, disabled? }`. `content` is a Snippet for the panel. |
value | string | First enabled item | No | Bindable | The selected tab. |
activationMode | 'automatic' | 'manual' | automatic | No | One-way | Automatic selects on arrow keys. Manual waits for Enter or Space. |
class | string | "" | No | One-way | Extra classes, added after the component classes. |
Forwarded attributes
None. Tabs forwards no attributes.
The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Tabs documentation. Only the props listed on this page are part of the Tabs contract. No data attributes are documented as stable.
Limits
- The list reuses the measured segmented track. Using it for tabs is an adaptation.
- Horizontal only. Inactive panels stay mounted and hidden, so their state survives a switch.