Tabs
Switchable content panels.
Anatomy
<script>
import { Tabs } from '@shardsui/svelte/tabs'
</script>
<Tabs.Root>
<Tabs.List>
<Tabs.Tab value="..." />
<Tabs.Indicator />
</Tabs.List>
<Tabs.Panel value="..." />
</Tabs.Root>Every Tabs.Tab needs a value, and the Tabs.Panel it controls repeats it.
Examples
Animated panels
Animate panels as they activate using the data-starting-style and data-ending-style attributes. The data-activation-direction attribute indicates which direction the newly active tab is relative to the previously active one, letting panels slide in from the correct side.
Links
When a tab navigates to a URL instead of toggling a panel, render it as an anchor: set as="a" on <Tabs.Tab>. The href is forwarded to the element, and the tab keeps its role="tab" and its place in the list's keyboard navigation.
<Tabs.Root>
<Tabs.List>
<Tabs.Tab as="a" href="/overview" value="overview">Overview</Tabs.Tab>
</Tabs.List>
</Tabs.Root>API reference
Root
Groups the tabs and the corresponding panels.
Renders a <div> element.
List
Groups the individual tab buttons into one tab stop; arrow keys move between them.
Renders a <div> element with role="tablist".
Tab
An individual interactive tab button that toggles the corresponding panel.
Renders a <button> element.
Indicator
A visual indicator that can be styled to match the position of the currently active tab. Place it inside <Tabs.List> — it is measured against the list — and position it with the CSS variables below.
Renders a <span> element; nothing renders while the active value is null.
Panel
A panel displayed when the corresponding tab is active.
Renders a <div> element.
Additional types
TabsValue
The value identifying a tab, shared by Tabs.Root's value, Tabs.Tab's value and the
Tabs.Panel it controls.
type TabsValue = string | number | nullTabsOrientation
The orientation of Tabs.Root, which decides the arrow keys that move between tabs.
type TabsOrientation = 'horizontal' | 'vertical'TabsActivationDirection
Which way the active tab moved, handed to the children snippet as activationDirection and
mirrored on data-activation-direction.
type TabsActivationDirection = 'left' | 'right' | 'up' | 'down' | 'none'