Menu

Change language

GitHub repo

Tabs

tabsui

Horizontal tab navigation with content panels — pick one panel at a time. Underline or pills variants. Hand-rolled roving keyboard navigation with automatic activation.

Installation

$npx shadcn-svelte@latest add https://uipkge.dev/r/svelte/tabs.json
Manifest:https://uipkge.dev/r/svelte/tabs.jsonInstalls to:src/lib/components/ui/tabs/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
variantsegmentedoptional
orientation
'horizontal''vertical'
horizontaloptional
value

Controlled active value. Bind with `bind:value`.

string—optional
defaultValue

Initial active value for uncontrolled usage.

string—optional
refHTMLDivElement | null—optional
onValueChange(value: string) => void—optional

Schema

Type aliases from this item's source — use them to shape the data you pass in.

TabsContextValue
interface TabsContextValue {
  current: () => string | undefined
  orientation: () => TabsOrientation
  select: (value: string) => void
  triggerId: (value: string) => string
  contentId: (value: string) => string
}

npm dependencies

Used by

Files installed (7)

  • src/lib/components/ui/tabs/Tabs.svelte1.4 kB
    <script lang="ts" module>
      import type { HTMLAttributes } from 'svelte/elements'
      import type { TabsOrientation } from './context'
    
      export interface TabsProps extends HTMLAttributes<HTMLDivElement> {
        /** Controlled active value. Bind with `bind:value`. */
        value?: string
        /** Initial active value for uncontrolled usage. */
        defaultValue?: string
        orientation?: TabsOrientation
        ref?: HTMLDivElement | null
        onValueChange?: (value: string) => void
      }
    </script>
    
    <script lang="ts">
      import { cn } from '$lib/utils'
      import { nextTabsId, setTabsContext } from './context'
    
      let {
        class: className,
        defaultValue,
        value = $bindable(defaultValue),
        orientation = 'horizontal',
        children,
        ref = $bindable(null),
        onValueChange,
        ...restProps
      }: TabsProps = $props()
    
      const baseId = nextTabsId()
    
      function select(next: string) {
        value = next
        onValueChange?.(next)
      }
    
      setTabsContext({
        current: () => value,
        orientation: () => orientation,
        select,
        triggerId: (v: string) => `${baseId}-trigger-${v}`,
        contentId: (v: string) => `${baseId}-content-${v}`,
      })
    </script>
    
    <div
      bind:this={ref}
      data-uipkge=""
      data-slot="tabs"
      data-orientation={orientation}
      class={cn('flex w-full', orientation === 'vertical' ? 'flex-row gap-4' : 'flex-col gap-2', className)}
      {...restProps}
    >
      {@render children?.()}
    </div>
    
  • src/lib/components/ui/tabs/TabsContent.svelte1.4 kB
  • src/lib/components/ui/tabs/TabsList.svelte6.7 kB
  • src/lib/components/ui/tabs/TabsTrigger.svelte1.5 kB
  • src/lib/components/ui/tabs/tabs.variants.ts4.3 kB
  • src/lib/components/ui/tabs/context.ts0.9 kB
  • src/lib/components/ui/tabs/index.ts0.5 kB

Raw manifest:https://uipkge.dev/r/svelte/tabs.json