Skip to main content

Tabs

Switch between peer panels with managed focus and activation.

High-level metrics and system activity overview.

Props
Slots

Anatomy#

Tabs [component; slot=root]
├── list [slot]
│   ├── indicator [slot]
│   └── trigger [slot]
│       ├── leading [slot]
│       └── label [slot]
└── content [slot]

String labels use the label slot; JSX labels render directly inside the trigger.

Usage#

Use Tabs to switch between peer panels while staying in the same page context. Use navigation links when each destination needs its own URL and document state. Use Stepper for a fixed sequence. Use NavigationMenu for website destinations with expandable panels.

import { Tabs } from 'moraine'

export function Example() {
  return <Tabs items={[{ value: 'account', label: 'Account', content: 'Profile settings' }]} />
}

Selected value#

Use value with onValueChange for controlled tabs, or defaultValue for an initial local selection. Without a matching enabled value, the first enabled tab is active. onValueChange fires only when the user selects a different tab. Disabled items, and every tab while disabled is set, cannot be selected; keyboard navigation skips disabled items.

Every item requires a unique value (an item that repeats an earlier value is disabled) and can set icon to render an icon before the label.

Only the selected tab’s panel is mounted. For JSX panel content, pass a component as content: Tabs renders it with { value } only while its tab is selected, so an unselected panel is never built. This matters in SSR and MDX, where building a panel eagerly can emit markup the hydrated tree does not expect.

<Tabs
  value={tab()}
  onValueChange={setTab}
  items={[
    { value: 'overview', label: 'Overview', content: () => <OverviewPanel /> },
    {
      value: 'billing',
      label: 'Billing',
      content: (props) => <Billing value={props.value} />,
    },
  ]}
/>

Activation and keyboard#

activationMode="automatic" (the default) selects a tab as arrow navigation moves focus. In manual mode, arrows move focus and Enter or Space selects.

loop (default true) wraps navigation at the first and last enabled tabs, and the arrow keys that move focus follow the list orientation. aria-label and aria-labelledby on Tabs name the tablist, not the root element.

<Tabs items={TABS} activationMode="automatic" defaultValue="overview" />
<Tabs items={TABS} activationMode="manual" defaultValue="overview" />
Key Description
Arrow keys Moves focus among enabled tabs by orientation.
↖ / ↘ Moves focus to the first or last enabled tab.
↵ / Space Activates the focused tab in manual mode.
⇥ Leaves the tab list according to normal focus order.

Examples#

Controlled#

Control the active tab with value and onValueChange.

import { Tabs } from 'moraine'
import type { TabsT } from 'moraine'
import { createSignal } from 'solid-js'

const TAB_ITEMS: TabsT.Item[] = [
  {
    value: 'account',
    label: 'Account',
    icon: 'i-lucide:user',
    content: () => (
      <div class="text-xs text-muted-foreground mt-2 p-3 b-1 b-border rounded-lg bg-card/40">
        Manage your account preferences, profile details, and email notifications.
      </div>
    ),
  },
  {
    value: 'security',
    label: 'Security',
    icon: 'i-lucide:shield',
    content: () => (
      <div class="text-xs text-muted-foreground mt-2 p-3 b-1 b-border rounded-lg bg-card/40">
        Configure two-factor authentication, active sessions, and API tokens.
      </div>
    ),
  },
  {
    value: 'billing',
    label: 'Billing',
    icon: 'i-lucide:credit-card',
    content: () => (
      <div class="text-xs text-muted-foreground mt-2 p-3 b-1 b-border rounded-lg bg-card/40">
        View past invoices, payment methods, and current subscription usage.
      </div>
    ),
  },
]

export function SelectionUsage() {
  const [tab, setTab] = createSignal('account')

  return (
    <div class="max-w-md w-full space-y-3">
      <Tabs items={TAB_ITEMS} value={tab()} onValueChange={setTab} />
      <p class="text-xs text-muted-foreground">
        Active tab: <span class="text-foreground font-medium font-mono">{tab()}</span>
      </p>
    </div>
  )
}

Manual activation#

activationMode="manual" moves focus with arrow keys and switches panels only on Enter or Space. Use it when selecting a tab is expensive, such as a panel that fetches data.

import { Tabs } from 'moraine'
import type { TabsT } from 'moraine'

const SETTINGS_TABS: TabsT.Item[] = [
  {
    label: 'General',
    value: 'general',
    icon: 'i-lucide:sliders',
    content: () => (
      <div class="p-3 space-y-1">
        <h4 class="text-sm font-semibold">Workspace defaults</h4>
        <p class="text-xs text-muted-foreground">
          Name, timezone, and default branch. Arrow keys move focus; Enter or Space opens the panel.
        </p>
      </div>
    ),
  },
  {
    label: 'Deployments',
    value: 'deployments',
    icon: 'i-lucide:rocket',
    content: () => (
      <div class="p-3 space-y-1">
        <h4 class="text-sm font-semibold">Deployment gates</h4>
        <p class="text-xs text-muted-foreground">
          Require reviews before production. Manual activation keeps the previous panel visible
          until you confirm.
        </p>
      </div>
    ),
  },
  {
    label: 'Notifications',
    value: 'notifications',
    icon: 'i-lucide:bell',
    content: () => (
      <div class="p-3 space-y-1">
        <h4 class="text-sm font-semibold">Alert rules</h4>
        <p class="text-xs text-muted-foreground">Configure webhook dispatch channels.</p>
      </div>
    ),
  },
]

export function ActivationMode() {
  return (
    <div class="max-w-md w-full">
      <Tabs items={SETTINGS_TABS} activationMode="manual" defaultValue="general" />
    </div>
  )
}

API Reference#

Attributes#

Attributes
data-disabled
Slot: tabstabs-trigger
Description: Present when the component, slot, or item is disabled.
data-highlighted
Slot: tabs-trigger
Description: Present when the item is highlighted by pointer or keyboard navigation.
data-selected
Slot: tabs-triggertabs-content
Description: Present when the item or tab is selected.

Props#

Props for the Tabs component. Renders a <div> element by default.

Prop