Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Selection and preferences

useTabs

Manages a tabbed interface with controlled/uncontrolled value, arrow key navigation, roving tabindex, and automatic ARIA attributes for tab triggers and panels.

Live component preview · Astro

Explore Tabs

Try the component this hook connects to. The preview uses the Astro adapter; the React example below uses useTabs.

All primitives are available as Astro components.

The same API surface is available in React.

Standards-based custom elements bring Lumen to framework-neutral pages.

React Native consumes the shared tokens and native component contracts.

SwiftUI provides native Apple-platform primitives.

Compose provides native Android and Wear OS primitives.

React usage

Import from @santi020k/lumen-react and spread the controller props onto the matching components.

tsxuseTabs example
import { Tabs, TabsList, TabsTrigger, TabsPanel } from '@santi020k/lumen-react'
import { useTabs } from '@santi020k/lumen-react'

export function SettingsTabs() {
  const tabs = useTabs({ defaultValue: 'general' })

  return (
    <Tabs {...tabs.rootProps}>
      <TabsList {...tabs.listProps}>
        <TabsTrigger {...tabs.getTriggerProps('general')}>General</TabsTrigger>
        <TabsTrigger {...tabs.getTriggerProps('security')}>Security</TabsTrigger>
      </TabsList>
      <TabsPanel {...tabs.getPanelProps('general')}>
        <p>General settings content.</p>
      </TabsPanel>
      <TabsPanel {...tabs.getPanelProps('security')}>
        <p>Security settings content.</p>
      </TabsPanel>
    </Tabs>
  )
}
import { Tabs, TabsList, TabsTrigger, TabsPanel } from '@santi020k/lumen-react'
import { useTabs } from '@santi020k/lumen-react'

export function SettingsTabs() {
  const tabs = useTabs({ defaultValue: 'general' })

  return (
    <Tabs {...tabs.rootProps}>
      <TabsList {...tabs.listProps}>
        <TabsTrigger {...tabs.getTriggerProps('general')}>General</TabsTrigger>
        <TabsTrigger {...tabs.getTriggerProps('security')}>Security</TabsTrigger>
      </TabsList>
      <TabsPanel {...tabs.getPanelProps('general')}>
        <p>General settings content.</p>
      </TabsPanel>
      <TabsPanel {...tabs.getPanelProps('security')}>
        <p>Security settings content.</p>
      </TabsPanel>
    </Tabs>
  )
}

Load @santi020k/lumen-react/styles.css once in your application. With React Server Components, put 'use client' at the top of the module that calls the hook. Follow the React setup guide for the framework boundary.

Options

PropertyTypeDefaultDescription
defaultValuestring""Initial active tab value for uncontrolled usage.
valuestring-Controlled active tab value.
onValueChange(value: string) => void-Callback fired when the active tab changes.
orientation"horizontal" | "vertical""horizontal"Tab navigation direction — affects which arrow keys are used.
idstringautoBase id for generated tab and panel ids.

Controller return values

PropertyTypeDescription
rootPropsLumenProps<"div">Spread onto the tabs root wrapper.
listPropsLumenProps<"div">Spread onto the tablist element.
getTriggerProps(value)(value, props?) => LumenProps<"button">Returns props for a tab trigger with the given value. Includes aria-selected, role, keyboard handlers.
getPanelProps(value)(value, props?) => LumenProps<"div">Returns props for a tab panel. Automatically hides non-active panels.
valuestringCurrently active tab value.
setValueDispatch<SetStateAction<string>>State setter for controlled usage.
rootRefRefObject<HTMLElement>Ref to the tabs root element.
Web docsFull catalog