Tabs

React Tabs components are used to organize related content into separate panels that share the same context. They are commonly used in dashboards, settings pages, profile views, and any interface where users need to switch between sections without leaving the page.

This Tabs component is built with React and react-aria-components, and styled with Tailwind CSS and the Tailgrids theme tokens. It supports multiple visual variants, icons, badges, and vertical or horizontal layouts while keeping tab behavior accessible and predictable.

Overview

Get a high-level view of your dashboard metrics and key performance indicators.

Installation

Anatomy

Import the tab parts and compose them to build the layout.

import {
  Tabs,
  TabsList,
  TabsTrigger,
  TabsContent
} from "@/components/tailgrids/tabs";

const TabsExample = () => (
  <Tabs defaultSelectedKey="tab1">
    <TabsList>
      <TabsTrigger id="tab1" />
      <TabsTrigger id="tab2" />
    </TabsList>
    <TabsContent id="tab1" />
    <TabsContent id="tab2" />
  </Tabs>
);

export default TabsExample;

Usage

Import the components and use the default variant to create a standard tabbed interface.

import {
  TabsContent,
  TabsList,
  Tabs,
  TabsTrigger
} from "@/components/tailgrids/tabs";

export default function TabsExample() {
  return (
    <Tabs defaultSelectedKey="overview">
      <TabsList>
        <TabsTrigger id="overview">Overview</TabsTrigger>
        <TabsTrigger id="analytics">Analytics</TabsTrigger>
        <TabsTrigger id="reports">Reports</TabsTrigger>
      </TabsList>
      <TabsContent id="overview">
        <p>Overview content goes here.</p>
      </TabsContent>
      <TabsContent id="analytics">
        <p>Analytics content goes here.</p>
      </TabsContent>
      <TabsContent id="reports">
        <p>Reports content goes here.</p>
      </TabsContent>
    </Tabs>
  );
}

Note: Only one tab panel is visible at a time. The defaultSelectedKey prop sets the initially active tab.

Examples

Variants

Use the variant prop to control the visual style of the tab list. Supported values are default and line.

Default

Welcome to your home dashboard. Here you can see recent activities.

Line

Welcome to your home dashboard. Here you can see recent activities.

With Icons

Render an icon as a child of TabsTrigger, before the tab label.

Access your main dashboard and summary.

Note: Icons are automatically sized to 20px (1.25rem).

With Badges

Render a Badge as a child of TabsTrigger to display a notification count or status indicator next to the label.

You have 12 new messages in your inbox.

Note: Badges use the Badge component with primary color.

Vertical Orientation

Set the orientation prop to vertical on Tabs to arrange the tab list vertically beside the content panel.

Team Management

Manage your team members, roles, and permissions. Add new members or update existing ones.

Note: Vertical orientation is responsive and wraps on small screens.

Custom

You can customize the tab appearance using standard Tailwind CSS classes.

Overview

Your performance metrics for this week

Revenue
$24.5k+12%
Users
1,234+8.4%

API Reference

Tabs

The root container. Wraps React Aria Tabs.

PropTypeDefaultDescription
defaultSelectedKeystring-Initially selected tab (id of a TabsTrigger)
selectedKeystring-Controlled selected tab
onSelectionChange(key: Key) => void-Called when the selected tab changes
variant'default' | 'line''default'Visual style, forwarded to TabsList/TabsTrigger
orientation'horizontal' | 'vertical''horizontal'Layout orientation
classNamestring-Additional CSS classes

TabsList

Container for tab triggers. Wraps React Aria TabList.

PropTypeDescription
variant'default' | 'line'Overrides the variant set on Tabs
classNamestringAdditional CSS classes
childrenReact.ReactNodeTabsTrigger components

TabsTrigger

Individual tab. Wraps React Aria Tab. Render icons and badges as children.

PropTypeDescription
idstringUnique tab identifier (required)
isDisabledbooleanDisables the tab
variant'default' | 'line'Overrides the variant set on Tabs
classNamestringAdditional CSS classes
childrenReact.ReactNodeTab label, with optional icon and Badge
Data AttributeValuesDescription
data-selected"true" | "false"Indicates whether the tab is selected.

TabsContent

Content panel for each tab. Wraps React Aria TabPanel.

PropTypeDescription
idstringTab identifier matching trigger (required)
classNamestringAdditional CSS classes
childrenReact.ReactNodePanel content

Accessibility

  • Built on React Aria Tabs, with proper ARIA attributes (role="tab", role="tabpanel", aria-selected, aria-controls, aria-labelledby)
  • Keyboard accessible with standard tab navigation
  • Active tab is clearly indicated with visual styling
  • Content panels are properly associated with their triggers
  • Hidden content uses hidden attribute for screen readers
  • Auto-generated unique IDs ensure proper associations