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. An item can also set icon, which renders 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 navigation#

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. The arrow keys that move focus follow the list orientation.

<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#

Account settings owned by page state#

Keep Account, Security, and Billing on one page. Store the selected tab in local state.

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>
  )
}

Browse dashboard tabs as focus moves#

activationMode="automatic" selects Overview, Analytics, or Logs while arrow keys move focus. Use this for lightweight inspection panels.

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

const TABS: TabsT.Item[] = [
  {
    value: 'overview',
    label: 'Overview',
    content: (
      <div class="text-xs text-muted-foreground p-3">System status and resource metrics.</div>
    ),
  },
  {
    value: 'analytics',
    label: 'Analytics',
    content: (
      <div class="text-xs text-muted-foreground p-3">Traffic breakdowns and request volume.</div>
    ),
  },
  {
    value: 'logs',
    label: 'Logs',
    content: (
      <div class="text-xs text-muted-foreground p-3">Real-time application execution stream.</div>
    ),
  },
]

export function ActivationUsage() {
  return (
    <div class="max-w-md w-full">
      <Tabs items={TABS} activationMode="automatic" defaultValue="overview" />
    </div>
  )
}

Confirm a settings tab with Enter#

activationMode="manual" keeps the current panel until Enter or Space. Use it when switching tabs should be an explicit commit, as in a settings wizard.

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