Skip to content

Tabs

A headless, accessible Tabs component for React. Composed of multiple subcomponents for flexible usage.

Features

  • Accessible (keyboard navigation, ARIA attributes)
  • Headless (no styles, fully customizable)
  • Composable API (Tabs, TabsList, Tab, TabsPanel)
  • Context-powered hooks

Installation

bash
npm install react-headless-ui-kit

Usage

tsx
import {
  Tabs,
  TabsList,
  Tab,
  TabsPanel,
  useTabs,
} from "react-headless-ui-kit";

function ExampleTabs() {
  return (
    <Tabs defaultIndex={0}>
      <TabsList style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
        <Tab index={0}>Tab One</Tab>
        <Tab index={1}>Tab Two</Tab>
        <Tab index={2}>Tab Three</Tab>
      </TabsList>
      <TabsPanel index={0}>
        <div>Content for Tab One</div>
      </TabsPanel>
      <TabsPanel index={1}>
        <div>Content for Tab Two</div>
      </TabsPanel>
      <TabsPanel index={2}>
        <div>Content for Tab Three</div>
      </TabsPanel>
    </Tabs>
  );
}

API Reference

<Tabs />

PropTypeDescription
childrenReactNodeTabs content
defaultIndexnumberInitial selected tab index

<TabsList />

Container for tab buttons.

PropTypeDescription
childrenReactNodeTab buttons

<Tab />

Individual tab button.

PropTypeDescription
indexnumberTab index
childrenReactNodeTab label

<TabsPanel />

Panel for tab content.

PropTypeDescription
indexnumberPanel index
childrenReactNodePanel content

useTabs()

Hook to access tabs context values inside subcomponents.

Return valueDescription
selectedIndexSelected tab index
setSelectedIndexSetter for index
tabRefsArray of tab refs
panelRefsArray of panel refs

Accessibility

  • Arrow keys navigate between tabs.
  • ARIA attributes are set for screen readers.
  • Only the selected panel is visible.

Customization

All components are unstyled. Use your own styles via className or style props.