Tabs
Related sections with keyboard, overflow, editing, snippets and saving panels.
When to use
Tabs switches related views in the same area. Line is suitable for page sections, card is for visually separated panels, editable-card is for adding and closing tabs. For the sequence of required steps, use Steps.
CSS Tabs Prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. Panels, navigation and more use the Tabs prefix. General slide animations and namespace themes are independent. Changing the name keeps the active tab and draft.
Keys and contents of panels
items contains stable string key, label signatures and children-snippets. defaultActiveKey specifies the initial selection; bind:activeKey synchronizes it with the application. disabled prevents the activation of a specific header.
| Problem | Setting | Example |
|---|---|---|
| Switch related views | items, bind:activeKey |
Main scenario |
| Place headers on side | tabPlacement |
Location |
| Open many tabs | overflow and scrolling | Long panel |
| Create and close panels | type="editable-card", onEdit |
Editable Tabs |
| Save or delete content | destroyOnHidden, forceRender |
Life cycle |
onChange reports the new active key. onTabClick receives key and MouseEvent; Cancellation via preventDefault allows you to prohibit the transition, for example, with an unconfirmed draft. Do not change the key along with the signature: the key determines the identity of the panel.
Life cycle and editing
By default, the panel is created on the first visit and saved after hiding. forceRender creates it in advance. destroyOnHidden removes hidden content; the setting of an individual item takes precedence over the general one, including false.
Removing resets local state and uncontrolled fields. For a draft that needs to survive being closed or unmounted, store the data in the application. animated can include indicator and panels separately; The presence of animation does not replace data management.
onEdit only communicates the add/remove intent. The application updates items, generates a unique key and selects the adjacent available activeKey after deletion. Closable:false protects the tab; hideAdd hides the add button. Your own way of adding shows the external button without changing the items contract.
Availability and design
Arrows move focus, Enter or Space activate the selected title. Manual activation allows you to view titles without launching each panel. Set an accessible tablist name via aria-label or aria-labelledby; locale separately translates the add and delete buttons and the list of hidden tabs.
ConfigProvider.tabs sets general defaults and semantic design. styles accepts CSS strings and objects. The style of root takes precedence over styles.root, tabBarStyle over styles.header. Tabs design tokens are applied via theme.components.Tabs. Slots, item settings and advanced more parameters are listed in the API.
Examples
General information about the project.
Basic tabs
The tab links the header to the tabpanel. Arrows move focus, Enter and Space activate the selected tab.
<script lang="ts">
import { Tabs } from '@woodger/antd';
</script>
<style>
p { margin:0; }
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<Tabs aria-label={("Basic sections")}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
General information about the project.
Inaccessible tab
disabled excludes the tab from selection and keyboard bypass. The example allows you to change the availability of settings.
<script lang="ts">
import { Tabs, Checkbox } from '@woodger/antd';
let disabled = $state(true);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div class="controls">
<Checkbox bind:checked={disabled}>
{("Settings tab not available")}
</Checkbox>
</div>
<Tabs aria-label={("Restricted sections")}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", disabled, children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
General information about the project.
Center
centered centers a horizontal list of titles as long as there is enough free space.
<script lang="ts">
import { Tabs } from '@woodger/antd';
</script>
<style>
p { margin:0; }
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<Tabs aria-label={("Centered sections")}
centered
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
General information about the project.
Heading icons
icon accepts Snippet. SVGs are decorative, the available tab name remains text.
<script lang="ts">
import { Tabs } from '@woodger/antd';
</script>
<style>
p { margin:0; }
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
{#snippet icon()}
<svg
aria-hidden="true"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
><path
d="M4 4h6v6H4Zm10 0h6v6h-6ZM4 14h6v6H4Zm10 0h6v6h-6Z"
/></svg>
{/snippet}
<Tabs aria-label={("Sections with icons")}
items={([
{ key: 'overview', label: "Overview", icon, children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", icon, children: activity }
])}
/>
General information about the project.
Indicator size and position
indicator.size takes a number or function of the header size; align uses Boolean start/center/end.
<script lang="ts">
import { Tabs, Checkbox, type TabsIndicator } from '@woodger/antd';
let half = $state(true);
let align = $state<NonNullable<TabsIndicator['align']>>('center');
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div class="controls">
<Checkbox bind:checked={half}>{("Half width header")}</Checkbox>
<label>{("Indicator alignment ")}<select bind:value={align}>
<option value="start">
{("At the beginning")}
</option>
<option value="center">
{("Center")}
</option>
<option value="end">{("At the end")}</option>
</select></label>
</div>
<Tabs aria-label={("Sections with indicator")}
indicator={{ size: half ? origin => origin / 2 : 24, align }}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
Section selected: section-1
Many tabs
Tab labels scroll and overflow into the More menu. more.prefixCls sets the popup prefix, and more.overlayClassName retains the standard styles. onTabScroll reports the scroll direction.
<script lang="ts">
import { Tabs } from '@woodger/antd';
let activeKey = $state<string | undefined>('section-1');
let direction = $state(("No scrolling yet"));
</script>
<style>
p { margin:0; }
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet moreIcon()}{("More")}{/snippet}
{#snippet current()}<p>{("Section selected: ")}{activeKey}</p>{/snippet}
<Tabs aria-label={("Many sections")}
bind:activeKey
more={{
icon: moreIcon,
trigger: 'click',
prefixCls: 'section-tabs-more',
overlayClassName: 'ant-tabs-dropdown'
}}
locale={{ dropdownAriaLabel: "Hidden sections" }}
onTabScroll={info => { direction = info.direction; }}
items={([
...Array.from({ length: 16 }, (_, index) => ({
key: `section-${index + 1}`, label: `Section ${index + 1}`, children: current
}))
])}
/>
<output aria-label={("Scrolling Tabs headers")}>{direction}</output>
General information about the project.
Actions next to tabs
tabBarExtraContent accepts a Snippet or a left/right pair. Actions are not tabs and have their own handlers.
<script lang="ts">
import { Tabs, Button } from '@woodger/antd';
let action = $state(("No action"));
</script>
<style>
p { margin:0; }
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
{#snippet leftAction()}<Button size="small" onclick={() => {
action = ("Update requested");
}}>{("Update")}</Button>{/snippet}
{#snippet rightAction()}<Button size="small" onclick={() => {
action = ("Data saved");
}}>{("Save")}</Button>{/snippet}
<Tabs aria-label={("Sections with actions")}
tabBarExtraContent={{ left: leftAction, right: rightAction }}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
<output aria-label={("Action next to Tabs")}>{action}</output>
General information about the project.
Tabs sizes
Local size takes precedence over the gallery setting. medium means regular size.
<script lang="ts">
import { Tabs, type TabsProps } from '@woodger/antd';
let size = $state<TabsProps['size']>('medium');
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div class="controls"><label>{("Tabs size ")}<select bind:value={size}>
<option value="small">small</option><option value="medium">medium</option>
<option value="large">large</option>
</select></label></div>
<Tabs aria-label={("Sections of selected size")}
{size}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
General information about the project.
Location and RTL
tabPlacement specifies top/bottom/start/end. The logical sides are reflected along with the direction of the interface.
<script lang="ts">
import { Tabs, Checkbox, ConfigProvider, type TabsPlacement } from '@woodger/antd';
let placement = $state<TabsPlacement>('top');
let rtl = $state(false);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div class="controls">
<label>{("Tabs side ")}<select bind:value={placement}>
<option value="top">
{("Top")}
</option>
<option value="bottom">
{("Bottom")}
</option>
<option value="start">
{("At the beginning")}
</option>
<option value="end">
{("At the end")}
</option>
</select></label>
<Checkbox bind:checked={rtl}>{("RTL placement Tabs")}</Checkbox>
</div>
<ConfigProvider direction={rtl ? 'rtl' : 'ltr'}>
<Tabs aria-label={("Partition location")}
tabPlacement={placement} style="min-height:180px"
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
</ConfigProvider>
Open report: report-1
Find hidden tab
popupRender adds search and jump to first match in restTabs. The original list is saved in its entirety along with its ARIA links and keyboard.
<script lang="ts">
import type { Snippet } from 'svelte';
import { Button, Input, Tabs, type TabsMoreRenderInfo } from '@woodger/antd';
let activeKey = $state<string | undefined>('report-1');
let query = $state('');
</script>
<style>
.search {
box-sizing: border-box;
width: 280px;
max-width: calc(100vw - 32px);
padding: 12px;
color: var(--ant-color-text);
background: var(--ant-color-bg-elevated);
border-radius: var(--ant-border-radius-lg);
box-shadow: var(--ant-box-shadow-secondary);
}
form {
display: grid;
gap: 12px;
margin-bottom: 12px;
}
label {
display: grid;
gap: 6px;
}
p { margin:0; }
</style>
{#snippet content()}<p>{("Open report: ")}{activeKey}</p>{/snippet}
{#snippet moreIcon()}{("More")}{/snippet}
{#snippet popupRender(menu: Snippet, info: TabsMoreRenderInfo)}
{@const matches = info.restTabs.filter(item => !item.disabled && typeof item.label === 'string'
&& item.label.toLocaleLowerCase('ru').includes(query.trim().toLocaleLowerCase('ru')))}
<div class="search">
<form onsubmit={event => {
event.preventDefault();
const item = matches[0];
if (!item || !query.trim()) {
return;
}
activeKey = item.key;
query = '';
info.onClose();
}}>
<label>{("Find hidden report")}<Input bind:value={query} placeholder={("For example, 20")} /></label>
<p role="status" aria-label={("Matches Tabs")}>{(query ? `Found: ${matches.length}` : "Search among hidden tabs")}</p>
<Button htmlType="submit" disabled={!query.trim() || !matches.length}>
{("Open found tab")}
</Button>
</form>
{@render menu()}
</div>
{/snippet}
<Tabs aria-label={("Reports with search")} bind:activeKey
more={{ icon: moreIcon, trigger: 'click', popupRender }}
locale={{ dropdownAriaLabel: "Hidden reports" }}
items={(Array.from({ length: 20 }, (_, index) => ({
key: `report-${index + 1}`, label: `Report ${index + 1}`, children: content
})))}
/>
General information about the project.
Card tabs
type=card is suitable for individual views. The style of the panel is set via semantic content, and the environment belongs to the example.
<script lang="ts">
import { Tabs } from '@woodger/antd';
</script>
<style>
p { margin:0; }
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div style="
padding: 16px;
background: var(--ant-color-fill-quaternary);
border-radius: 8px;
">
<Tabs aria-label={("Card sections")}
type="card" styles={{ content: `
padding: 16px;
background: var(--ant-color-bg-container);
` }}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
</div>
Adding and closing
onEdit requests the application to change items. The example selects the adjacent tab when deleting the active one and protects the “Browse” via closable=false.
<script lang="ts">
import { Tabs, type TabsItem } from '@woodger/antd';
let panes = $state<TabsItem[]>([
{ key: 'overview', label: "Overview", closable: false },
{ key: 'notes', label: "Notes" }
]);
let activeKey = $state<string | undefined>('overview');
let nextKey = 0;
function edit(target: MouseEvent | KeyboardEvent | string, action: 'add' | 'remove') {
if (action === 'add') {
const key = `new-${++nextKey}`;
panes = [...panes, { key, label: `Note ${nextKey}` }];
activeKey = key;
return;
}
if (typeof target !== 'string') {
return;
}
const index = panes.findIndex(item => item.key === target);
if (index < 0 || panes[index].closable === false || panes[index].disabled) {
return;
}
const next = panes.filter(item => item.key !== target);
if (activeKey === target) activeKey = next[Math.max(0, index - 1)]?.key;
panes = next;
}
</script>
<style>
label {
display: grid;
gap: 6px;
}
input {
box-sizing: border-box;
max-width: 100%;
}
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet pane()}<label>{("Draft tab")}<input value="" /></label>{/snippet}
<Tabs type="editable-card" bind:activeKey onEdit={edit}
locale={{ addAriaLabel: "Add tab", removeAriaLabel: "Close tab" }}
aria-label={("Editable sections")} items={(panes.map(item => ({
...item,
children: pane
})))}
/>
<output aria-label={("Editable Tabs")}>{("Open: ")}{(panes.length)}{("; active: ")}{activeKey}</output>
Open: main
Your own way of adding
hideAdd removes the standard plus. The outer button updates items and activeKey, closing remains the standard onEdit.
<script lang="ts">
import { Button, Tabs, type TabsItem } from '@woodger/antd';
let panes = $state<TabsItem[]>([{ key: 'main', label: "Main", closable: false }]);
let activeKey = $state<string | undefined>('main');
let nextKey = 0;
function add() {
const key = `draft-${++nextKey}`;
panes = [...panes, { key, label: `Draft ${nextKey}` }];
activeKey = key;
}
function edit(target: MouseEvent | KeyboardEvent | string, action: 'add' | 'remove') {
if (action === 'add' || typeof target !== 'string') {
return;
}
panes = panes.filter(item => item.key !== target);
if (activeKey === target) activeKey = panes[0]?.key;
}
</script>
<style>
.controls { margin-bottom:16px; }
</style>
{#snippet content()}<p>{("Open: ")}{activeKey}</p>{/snippet}
<div class="controls"><Button onclick={add}>{("New draft")}</Button></div>
<Tabs type="editable-card" hideAdd bind:activeKey onEdit={edit}
locale={{ removeAriaLabel: "Close draft" }} aria-label={("Sections with your own addition")}
items={(panes.map(item => ({ ...item, children: content })))}
/>
Contents of the first section.
Own panel shell
renderTabBar gets allowed props and DefaultTabBar. The example preserves the original navigation and adds styling to it.
<script lang="ts">
import { Tabs, type TabsDefaultTabBar, type TabsTabBarProps } from '@woodger/antd';
</script>
<style>
.bar {
margin-bottom: 16px;
padding: 8px;
border: 1px solid var(--ant-color-primary-border);
border-radius: 8px;
}
p { margin:0; }
</style>
{#snippet renderTabBar(props: TabsTabBarProps, DefaultTabBar: TabsDefaultTabBar)}
<div class="bar">
{@render DefaultTabBar({
...props,
style: [props.style, 'margin-bottom:0'].filter(Boolean).join(';')
})}
</div>
{/snippet}
{#snippet first()}<p>{("Contents of the first section.")}</p>{/snippet}
{#snippet second()}<p>{("Contents of the second section.")}</p>{/snippet}
<Tabs {renderTabBar} aria-label={("Sections with their own panel")} items={([
{ key: 'first', label: "First", children: first },
{ key: 'second', label: "Second", children: second }
])} />
Tab order
Native desktop drag and drop uses renderTabBar and native attributes. Buttons move the active tab from the keyboard; DnD Kit animations do not play.
<script lang="ts">
import {
Button,
Tabs,
type TabsItem,
type TabsTabNode,
type TabsTabAttributes,
type TabsTabBarProps,
type TabsDefaultTabBar
} from '@woodger/antd';
let items = $state<TabsItem[]>([
{ key: 'first', label: "First" }, { key: 'second', label: "Second" },
{ key: 'third', label: "Third" }
]);
let activeKey = $state<string | undefined>('second');
let dragged = '';
let activeIndex = $derived(items.findIndex(item => item.key === activeKey));
function move(source: string, target: string) {
const from = items.findIndex(item => item.key === source);
const to = items.findIndex(item => item.key === target);
if (from < 0 || to < 0 || from === to) {
return;
}
const next = [...items];
const [item] = next.splice(from, 1);
if (!item) {
return;
}
next.splice(to, 0, item);
items = next;
}
function shift(delta: number) {
const neighbor = items[activeIndex + delta];
if (neighbor && activeKey) move(activeKey, neighbor.key);
}
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
label {
display: grid;
gap: 6px;
}
input {
box-sizing: border-box;
max-width: 100%;
}
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet pane()}<label>{("Draft of rearranged tab")}<input
value=""
/></label>{/snippet}
{#snippet wrapTab(node: TabsTabNode, item: TabsItem, attributes: TabsTabAttributes)}
{@render node({
...attributes,
draggable: !item.disabled,
style: [attributes.style, 'cursor:grab'].filter(Boolean).join(';'),
ondragstart: event => {
attributes.ondragstart?.(event);
if (event.defaultPrevented) {
return;
}
dragged = item.key;
event.dataTransfer?.setData('text/plain', item.key);
},
ondragover: event => {
attributes.ondragover?.(event);
if (dragged) event.preventDefault();
},
ondrop: event => {
attributes.ondrop?.(event);
if (event.defaultPrevented || !dragged) {
return;
}
event.preventDefault();
move(dragged, item.key);
dragged = '';
},
ondragend: event => {
attributes.ondragend?.(event);
dragged = '';
}
})}
{/snippet}
{#snippet renderTabBar(props: TabsTabBarProps, DefaultTabBar: TabsDefaultTabBar)}
{@render DefaultTabBar({ ...props, children: wrapTab })}
{/snippet}
<div class="controls">
<Button disabled={activeIndex <= 0} onclick={() => shift(-1)}>
{("Move active to the left")}
</Button>
<Button disabled={activeIndex < 0 || activeIndex >= items.length - 1}
onclick={() => shift(1)}>{("Shift active to the right")}</Button>
</div>
<Tabs {renderTabBar} bind:activeKey aria-label={("Rearranged partitions")}
items={(items.map(item => ({ ...item, children: pane })))} />
<output
aria-label={("Tab order")}
>{items.map(item => item.label).join(' → ')}</output>
General information about the project.
Semantic styles and ConfigProvider
Global tabs configuration is created by root; the local styles function complements the header and panels. The provider and component classes are preserved.
<script lang="ts">
import { Tabs, Checkbox, ConfigProvider } from '@woodger/antd';
let card = $state(false);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div
class="controls"
><Checkbox
bind:checked={card}
>{("Card design Tabs")}</Checkbox></div>
<ConfigProvider tabs={({
classNames: { root: 'provider-tabs-root' },
styles: {
root: `
padding: 12px;
border: 1px solid var(--ant-color-primary-border);
border-radius: 8px;
`
}
})}>
<Tabs aria-label={("Designed sections")}
type={card ? 'card' : 'line'}
classNames={{ header: 'semantic-tabs-header', content: 'semantic-tabs-content' }}
styles={({ props }) => ({
header: 'background:var(--ant-color-fill-quaternary)',
content: props.type === 'card'
? 'padding:16px'
: 'padding:8px'
})}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
</ConfigProvider>
General information about the project.
Component tokens
Local theme changes the header spacing and color of the selected tab. The numeric control updates the horizontalItemGutter.
<script lang="ts">
import { Tabs, ConfigProvider, theme } from '@woodger/antd';
const tokens = theme.useToken();
let gutter = $state(20);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div
class="controls"
><label>{("Header spacing ")}<input
type="range"
min="12"
max="40"
bind:value={gutter}
/>
<output>{gutter}px</output>
</label></div>
<ConfigProvider theme={{
cssVar: {}, components: {
Tabs: {
horizontalItemGutter: gutter,
inkBarColor: tokens.token.colorSuccess,
itemSelectedColor: tokens.token.colorSuccess
}
}
}}>
<Tabs aria-label={("Sections with their own theme")}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
</ConfigProvider>
Saving and deleting panels
By default, a visited panel remains in the DOM and retains an uncontrolled field. destroyOnHidden removes it; after returning, a new field is created.
<script lang="ts">
import { Checkbox, Tabs } from '@woodger/antd';
let destroy = $state(false);
</script>
<style>
.controls { margin-bottom:16px; }
label {
display: grid;
gap: 6px;
}
input {
box-sizing: border-box;
max-width: 100%;
}
</style>
{#snippet draft()}<label>{("Draft example Tabs")}<input
value="Исходный черновик"
/></label>{/snippet}
{#snippet preview()}
<p>
{("Return to “Draft” to check that the field has been saved.")}
</p>
{/snippet}
<div
class="controls"
><Checkbox
bind:checked={destroy}
>{("Remove hidden panels")}</Checkbox></div>
<Tabs
destroyOnHidden={destroy}
aria-label={("Partition life cycle")}
items={([
{ key: 'draft', label: "Draft", children: draft },
{ key: 'preview', label: "View", children: preview }
])}
/>
General information about the project.
Panel animation
animated controls the indicator and panels separately. Panel animation is enabled at the user's discretion; reduced motion is taken into account by the library.
<script lang="ts">
import { Tabs, Checkbox } from '@woodger/antd';
let animate = $state(false);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div
class="controls"
><Checkbox
bind:checked={animate}
>{("Animation of Tabs panels")}</Checkbox></div>
<Tabs aria-label={("Animated sections")}
animated={{ inkBar: true, tabPane: animate }}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
General information about the project.
Events and transition cancellation
onTabClick reports a selection attempt, onChange reports a change in the active key. preventDefault in onTabClick leaves the current tab.
<script lang="ts">
import { Tabs, Checkbox } from '@woodger/antd';
let activeKey = $state<string | undefined>('overview');
let blocked = $state(false);
let events = $state<string[]>([]);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div
class="controls"
><Checkbox
bind:checked={blocked}
>{("Prevent changing tabs")}</Checkbox></div>
<Tabs aria-label={("Sections with events")}
bind:activeKey
onTabClick={(key, event) => {
events = [...events, `click:${key}`].slice(-5);
if (blocked) event.preventDefault();
}}
onChange={key => { events = [...events, `change:${key}`].slice(-5); }}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
<output aria-label={("Events Tabs")}>{(events.join(' → ')
|| ("No events"))}</output>
General information about the project.
RTL and logic sides
direction changes the tab direction and keyboard navigation order. tabPlacement="start" places the tabs at the logical start.
<script lang="ts">
import { Tabs, Checkbox } from '@woodger/antd';
let rtl = $state(true);
</script>
<style>
p { margin:0; }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
</style>
{#snippet overview()}<p>{("General information about the project.")}</p>{/snippet}
{#snippet settings()}<p>{("Access and notification settings.")}</p>{/snippet}
{#snippet activity()}<p>{("History of project changes.")}</p>{/snippet}
<div
class="controls"
><Checkbox
bind:checked={rtl}
>{("RTL logical tabs")}</Checkbox></div>
<Tabs aria-label={("Logical start of sections")}
direction={rtl ? 'rtl' : 'ltr'}
tabPlacement="start"
style={{ minHeight: '160px' }}
items={([
{ key: 'overview', label: "Overview", children: overview },
{ key: 'settings', label: "Settings", children: settings },
{ key: 'activity', label: "History", children: activity }
])}
/>
Enable reset to compare behavior: unsaved changes to a hidden panel will be lost.
Member Profile
Saved review example: profile drafts, settings, history and tabs inside Modal.
<script lang="ts">
import {
Button,
Checkbox,
Input,
Modal,
Table,
Tabs,
type TabsPlacement,
type TabsType
} from '@woodger/antd';
let activeKey = $state<string | undefined>('profile');
let tabPlacement = $state<TabsPlacement>('top');
let type = $state<TabsType>('line');
let destroyOnHidden = $state(false);
let modalOpen = $state(false);
let result = $state(("Change the profile and switch the tab - the draft will be saved."));
const history = [
{ key: 1, date: '25.10.2026', action: "Updated profile" },
{ key: 2, date: '24.10.2026', action: "Notifications enabled" }
];
function save(event: SubmitEvent) {
event.preventDefault();
const data = new FormData(event.currentTarget as HTMLFormElement);
result = ("Profile saved: " + String((data.get('displayName'))) + ".");
}
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 24px;
}
.settings label {
display: flex;
align-items: center;
gap: 8px;
}
select {
padding: 4px 8px;
color: var(--ant-color-text);
background: var(--ant-color-bg-container);
border: 1px solid var(--ant-color-border);
border-radius: 6px;
font: inherit;
}
.profile {
display: grid;
gap: 16px;
max-width: 360px;
}
.field {
display: grid;
gap: 6px;
}
.preferences {
display: grid;
gap: 16px;
}
.footer {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-top: 24px;
}
output, .note { color: var(--ant-color-text-secondary); }
.note { margin-top: 0; }
</style>
{#snippet profileIcon()}<span>↗</span>{/snippet}
{#snippet profile()}
<form class="profile" onsubmit={save}>
<label
class="field"
>{("Member name")}<Input
name="displayName"
defaultValue="Анна"
required
/></label>
<label class="field">{("Member Email")}<Input
name="email"
type="email"
defaultValue="anna@example.com"
required
/></label>
<div><Button
htmlType="submit"
type="primary"
>{("Save member profile")}</Button></div>
</form>
{/snippet}
{#snippet preferences()}
<div
class="preferences"
><Checkbox
defaultChecked
>
{("Receive project news")}
</Checkbox><Checkbox>
{("Receive a weekly report")}
</Checkbox></div>
{/snippet}
{#snippet activity()}
<Table
dataSource={(history)}
columns={([
{ key: 'date', title: "Date", dataIndex: 'date' },
{ key: 'action', title: "Event", dataIndex: 'action' }
])}
pagination={(false)}
caption={("Member history")}
scroll={{ x: 360 }}
/>
{/snippet}
{#snippet modalDescription()}
<p>
{("Tabs maintain the natural Tab order within the window.")}
</p>
{/snippet}
{#snippet modalNotes()}<label class="field">{("Note about the participant")}<Input
defaultValue="Новый участник проекта"
/></label>{/snippet}
<div class="settings">
<label>{("Tabs view ")}<select bind:value={type}>
<option value="line">
{("Line")}
</option>
<option
value="card"
>{("Cards")}</option>
</select></label>
<label>{("Tabs position ")}<select
bind:value={tabPlacement}
><option
value="top"
>{("Top")}</option><option
value="bottom"
>{("Bottom")}</option><option
value="start"
>{("At the beginning")}</option><option
value="end"
>{("At the end")}</option></select></label>
<Checkbox
bind:checked={destroyOnHidden}
>{("Reset content when hidden")}</Checkbox>
</div>
<p class="note">{("Enable reset to compare behavior: unsaved changes to a hidden panel will be lost.")}</p>
<Tabs
aria-label={("Member sections")}
items={([
{ key: 'profile', label: "Profile", icon: profileIcon, children: profile },
{ key: 'settings', label: "Settings", children: preferences },
{ key: 'access', label: "Access", disabled: true },
{ key: 'history', label: "History", children: activity }
])}
bind:activeKey
{type}
{tabPlacement}
{destroyOnHidden}
/>
<div class="footer"><Button onclick={() => { modalOpen = true; }}>
{("Open tabs in a window")}
</Button><output
aria-label={("Member Profile Result")}
>{result}</output></div>
<Modal bind:open={modalOpen} title={("Tabs in the card")}><Tabs
aria-label={("Card sections")}
items={([
{ key: 'description', label: "Description", children: modalDescription },
{ key: 'notes', label: "Notes", children: modalNotes }
])}
/></Modal>
Panels, navigation and More use the Tabs prefix. General slide animations and namespace themes are independent. Changing the name keeps the active tab and draft.
CSS prefixes Tabs
Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.
<script lang="ts">
import { Checkbox, ConfigProvider, Tabs, Input } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-tabs' : '');
let activeKey = $state('draft');
let draft = $state(("Draft tab"));
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix Tabs suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix Tabs")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'tabs-theme' } }}>
<div class="prefix-stage">
{#snippet ready()}{("Published")}{/snippet}
{#snippet editor()}
<Input bind:value={draft} aria-label={("Draft Tabs with prefix")} />
{/snippet}
<Tabs prefixCls={localPrefix} bind:activeKey items={([
{ key: 'draft', label: "Draft", children: editor },
{ key: 'ready', label: "Ready", children: ready }
])} />
</div>
</ConfigProvider>
<output aria-label={("CSS prefix Tabs")}>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("Panels, navigation and More use the Tabs prefix. General slide animations and namespace themes are independent. Changing the name keeps the active tab and draft.")}
</p>
</div>
API
Examples are checked against the current ant.design page and the public API of the installed package. Full definitions of Props are in @woodger/antd.
| Theme | Example or limitation |
|---|---|
| Basic | Related tab and tabpanel, keyboard. |
| Disabled | Dynamic availability. |
| Centered | Centering. |
| Icon | Decorative icon-snippets. |
| Indicator | Size and logical alignment. |
| Slide | Scrolling, more and onTabScroll. |
| Extra content | Independent actions left/right. |
| Size | Component size. |
| Placement | Logical sides and RTL. |
| Custom Popup Search | Search restTabs and go to match; the original list is retained in its entirety; in-place list filtering is not shown. |
| Card type tab | Cards and panel design. |
| Add & close tab | Changing items via onEdit. |
| Customized trigger of new tab | External button and hideAdd. |
| Customized bar of tab | DefaultTabBar in its shell. |
| Draggable Tabs | Public wrapper and native desktop drag and drop instead of React DnD Kit; buttons provide keyboard control. |
| Custom semantic dom styling | ConfigProvider.tabs and local styles. |
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and undefined inherit ConfigProvider. The namespace of the topic is set separately. | string | ConfigProvider.prefixCls + "-tabs" |
direction | Direction of the tabs and keyboard navigation. The local value takes precedence over the provider. | "ltr" | "rtl" | From ConfigProvider |
items | Keyed headers and panels. children and icon are passed to Snippet. | readonly TabsItem[] | [] |
activeKey | bind:activeKey binds the selected key to the application. | string | undefined | First available item |
defaultActiveKey | Read when created, does not reinitialize state after change. | string | First available item |
type | Tabs view; editable-card adds onEdit requests. | 'line' | 'card' | 'editable-card' | line |
onChange | Effective change of the active key. | (key: string) => void | — |
onTabClick | Attempting to activate. preventDefault cancels selections, including from the keyboard. | (key: string, event: MouseEvent) => void | — |
onEdit | Application changes items; add receives the event, remove receives the key. | (target: MouseEvent | KeyboardEvent | string, action: 'add' | 'remove') => void | — |
hideAdd | Removes the standard add button to editable-card. | boolean | false |
tabPlacement | Logical sides are reflected in RTL. | 'top' | 'bottom' | 'start' | 'end' | top |
size | medium indicates regular size. | 'small' | 'medium' | 'large' | From ConfigProvider |
centered | Centers horizontal headings when there is sufficient space. | boolean | false |
indicator | Numeric/functional size and logical align. | TabsIndicator | — |
tabBarGutter | Heading spacing in px. | number | From topic |
tabBarExtraContent | Content next to the list of titles. | TabsContent | { left?, right? } | — |
tabBarStyle | CSS title bars; overrides styles.header. | CSSStyle | — |
animated | The indicator and panels are configured separately. | boolean | TabsAnimatedConfig | inkBar: true, tabPane: false |
destroyOnHidden | Removes hidden panels; item may override the setting. | boolean | false |
more | The More menu supports prefixCls, popupRender, visible, and onVisibleChange. | TabsMoreProps | trigger: hover |
renderTabBar | User panel. DefaultTabBar supports children-wrapper with original attributes. | Snippet<[TabsTabBarProps, TabsDefaultTabBar]> | — |
onTabScroll | Physical direction of native scroll headers. | (info: TabsScrollInfo) => void | — |
locale | Available names add/remove and listbox; the tablist name is given by aria-label. | TabsLocale | Add tab / remove / expanded dropdown |
classNames | Semantic classes object or function. | TabsSemantic | — |
styles | CSS strings and objects for tab parts. The root style takes precedence over styles.root. | TabsSemantic<CSSStyle> | — |
nativeElement | bind:nativeElement returns the root after mount. | HTMLDivElement | — |
Panel Options
TabsItem specifies the required key/label, children, icon, disabled, closable, closeIcon, forceRender and destroyOnHidden. className/style refers to the panel. children/icon - Snippet; label also accepts text and a number. forceRender creates the content without the first selection.
Semantic DOM
Headings form a tablist with native tab buttons. Panels have role:tabpanel and aria-controls/aria-labelledby connections. Arrows, Home and End move focus between available headings; Enter and Space activate the selected one. A hidden visited panel preserves the DOM and is excluded from the accessible tree via hidden/aria-hidden; it also gets inert for the duration of the output animation.
Semantic slots: root, header, item, remove, indicator, body, content, popup.root. content refers to the panel, item refers to the header. Functions receive normalized props: tabPlacement - physical side, size stores information about an explicitly specified size.
ConfigProvider.tabs defines common classes, styles, indicator, add/remove icons and more.icon. The remaining global more fields do not change trigger, as in the pinned 6.6.8; set them locally. The nested provider replaces the entire record tabs.
Registration tokens
Component tokens work through ConfigProvider theme.components.Tabs. The card changes the title spacing, selected color, and indicator; shared tokens inherit the partition theme.
| Token | Purpose |
|---|---|
cardBg | Card header background. |
cardGutter | Card interval. |
cardHeight | Regular card height. |
cardHeightLG | Large card height. |
cardHeightSM | Low card height. |
cardPadding | Normal card indents. |
cardPaddingLG | Large card indents. |
cardPaddingSM | Small card indents. |
horizontalItemGutter | Horizontal header spacing. |
horizontalItemMargin | Horizontal margins of the header. |
horizontalItemMarginRTL | Horizontal margins in RTL. |
horizontalItemPadding | Horizontal header indents. |
horizontalItemPaddingLG | Large header indents. |
horizontalItemPaddingSM | Small header indents. |
horizontalMargin | Title bar indent. |
inkBarColor | Indicator color. |
itemActiveColor | Color when pressed. |
itemColor | Normal title color. |
itemHoverColor | Hover color. |
itemSelectedColor | Color of the selected title. |
titleFontSize | Regular font size. |
titleFontSizeLG | Large font. |
titleFontSizeSM | Small font. |
verticalItemMargin | Vertical margins. |
verticalItemPadding | Vertical header indents. |
zIndexPopup | Overflow menu layer. |
| Token | Current value |
|---|---|
colorBgContainer | #ffffff |
colorBorder | #d9d9d9 |
colorBorderSecondary | #f0f0f0 |
colorIcon | rgba(0,0,0,0.45) |
colorPrimaryBorder | #adc6ff |
colorText | rgba(0,0,0,0.88) |
colorTextDisabled | rgba(0,0,0,0.25) |
colorTextHeading | rgba(0,0,0,0.88) |
borderRadius | 6 |
borderRadiusLG | 8 |
boxShadowSecondary |
0 6px 16px 0 rgba(0,0,0,0.08),
0 3px 6px -4px rgba(0,0,0,0.12),
0 9px 28px 8px rgba(0,0,0,0.05)
|
controlHeight | 32 |
controlHeightLG | 40 |
controlItemBgHover | rgba(0,0,0,0.04) |
fontFamily | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 14 |
fontSizeSM | 12 |
lineHeight | 1.5714285714285714 |
lineHeightLG | 1.5 |
lineType | solid |
lineWidth | 1 |
lineWidthBold | 2 |
lineWidthFocus | 3 |
margin | 16 |
marginSM | 12 |
marginXS | 8 |
marginXXS | 4 |
motionDurationMid | 0.2s |
motionDurationSlow | 0.3s |
motionEaseInOut | cubic-bezier(0.645, 0.045, 0.355, 1) |
motionEaseInQuint | cubic-bezier(0.755, 0.05, 0.855, 0.06) |
motionEaseOutQuint | cubic-bezier(0.23, 1, 0.32, 1) |
paddingLG | 24 |
paddingSM | 12 |
paddingXXS | 4 |
FAQ
Why doesn't the arrow switch the panel?
Manual activation is used. After moving focus, press Enter or Space.
How to save a draft?
The visited panel is saved when destroyOnHidden:false. For DOM independence, store data in application state.
Who adds and closes tabs?
The application processes onEdit and updates items/activeKey. Use stable keys.
Why save the original menu in popupRender?
It contains keyboard logic and ARIA connections. Snippet can be supplemented with search, as in the example, without cloning the React element.
How to transfer a draggable example?
Save node, item and all attributes of the standard renderer. The local example extends desktop drag with rearrangement buttons.
Why is more not visible on the phone?
Mobile mode can hide the button while keeping scrolling titles.