Tabs

The Tabs component displays a group of buttons used to navigate between different views.


Default

A basic tab group with internal state and static content blocks.

Build the perfect messaging experience in 10 minutes.

<Tabs
tabs={[
  { label: "Home", content: <div>...</div> },
  { label: "Profile", content: <div>...</div> },
  { label: "Settings", content: <div>...</div> },
]}
/>

With icons

Each tab can optionally include an icon component before the label.

Explore the many out-of-the-box features of TalkJS.

<Tabs
tabs={[
  {
    label: (
      <span className="flex items-center gap-1.5">
        <Home className="w-4 h-4" /> Home
      </span>
    ),
    content: <Text as="p">...</Text>,
  },
  {
    label: (
      <span className="flex items-center gap-1.5">
        <View className="w-4 h-4" /> Components
      </span>
    ),
    content: <Text as="p">...</Text>,
  },
  {
    label: (
      <span className="flex items-center gap-1.5">
        <Wikis className="w-4 h-4" /> Customers
      </span>
    ),
    content: <Text as="p">...</Text>,
  },
]}
/>

Controlled selection

Pass selectedIndex and onSelectedIndexChange when the parent should manage selection. Clicking a tab requests a new index; the visible content changes when the parent updates selectedIndex.

Choose a language in either group. Both groups follow the same selection.

First example

const message = "Hello";

Second example

const message = "Hello";
const [selectedIndex, setSelectedIndex] = useState(0);

<Tabs
tabs={firstExampleTabs}
selectedIndex={selectedIndex}
onSelectedIndexChange={setSelectedIndex}
/>
<Tabs
tabs={secondExampleTabs}
selectedIndex={selectedIndex}
onSelectedIndexChange={setSelectedIndex}
/>

Indices start at 0. This example uses the same language order in both groups. For groups with different orders or available languages, keep a language identifier in the parent and map it to each group’s index. Remembering choices across pages also belongs to the parent.

Omit selectedIndex for the existing behaviour: each group manages its own selection and starts on the first tab. Keep a group either controlled or uncontrolled for its lifetime. An invalid or unavailable index displays the first tab; an empty tab list displays no content. Falling back does not trigger a callback.

The existing onChange(label) callback still runs on tab clicks, including when labels contain icons or other JSX. The new onSelectedIndexChange(index) callback provides the numeric index in either mode. Neither callback runs for parent-driven updates.


Props

  • tabs — Array of tab objects with label and content.
  • variant — Optional default or inverted appearance for light or dark content.
  • selectedIndex — Optional zero-based index controlled by the parent.
  • onSelectedIndexChange — Optional callback called with the clicked tab index.
  • onChange — Optional callback called with the selected label.

Usage

Import the Tabs component and define your tab label, content, and optional onChange handler.

import Tabs from "../../components/Tabs";
<Tabs
tabs={[
  { label: "Home", content: <div>...</div> },
  { label: "Profile", content: <div>...</div> },
]}
onChange={(label) => console.log("Selected:", label)}
/>