UI Kit components
UI Kit hooks
Forge bridge APIs
Jira bridge APIs
Upgrade UI Kit versions
Previous versions

Tabs

To add the Tabs component to your app:

1
2
import { Tabs } from '@forge/react';

Description

Tabs are used to organize content by grouping similar information on the same page.

Props

NameTypeRequiredDescription
childrenTabList | TabPanelYesThe children of Tabs. The first child should be a TabList filled with Tabs. Subsequent children should be TabPanels. There should be a Tab for each TabPanel. If you want to customize Tab or TabPanel, refer to the examples in the documentation.
idstringYesA unique ID that will be used to generate IDs for tabs and tab panels. This is required for accessibility purposes.
defaultSelectednumberNoThe index of the tab that will be selected by default when the component mounts. If not set, the first tab will be displayed by default.
onChange(index) => undefinedNoA callback function which will be fired when a tab is changed. It will be passed to the index of the selected tab and UIAnalyticsEvent.
selectednumberNoThe selected tab's index. If this prop is set, the component behaves as a controlled component. It will be up to you to listen to onChange.
shouldUnmountTabPanelOnChangebooleanNoTabs by default leave tab panels mounted on the page after they have been selected. If you would like to unmount a tab panel when it is not selected, set this prop to be true.

Examples

Default

The default form of tabs.

Example image of rendered tabs

1
2
import {Tabs, TabList, Tab, TabPanel, Box} from "@forge/react";

const TabsDefaultExample = () => {
  return (
    <Tabs id="default">
      <TabList>
        <Tab>Tab 1</Tab>
        <Tab>Tab 2</Tab>
        <Tab>Tab 3</Tab>
      </TabList>
      <TabPanel>
        <Box padding="space.300">
          This is the content area of the first tab.
        </Box>
      </TabPanel>
      <TabPanel>
        <Box padding="space.300">
          This is the content area of the second tab.
        </Box>
      </TabPanel>
      <TabPanel>
        <Box padding="space.300">
          This is the content area of the third tab.
        </Box>
      </TabPanel>
    </Tabs>
  );
};

Controlled

Tabs can be used as a controlled component.

Example image of controlled tabs

1
2
const TabsControlledExample = () => {
  const [selected, setSelected] = useState(0);

  const handleUpdate = (index) => setSelected(index);

  return (
    <>
      <Tabs id="controlled" onChange={handleUpdate} selected={selected}>
        <TabList>
          <Tab>Tab 1</Tab>
          <Tab>Tab 2</Tab>
          <Tab>Tab 3</Tab>
        </TabList>
        <TabPanel>
          <Box padding="space.300">
            This is the content area of the first tab.
          </Box>
        </TabPanel>
        <TabPanel>
          <Box padding="space.300">
            This is the content area of the second tab.
          </Box>
        </TabPanel>
        <TabPanel>
          <Box padding="space.300">
            This is the content area of the third tab.
          </Box>
        </TabPanel>
      </Tabs>
      <Button onClick={() => handleUpdate(2)}>
          Select the last tab
      </Button>
    </>
  );
};

Customize tab

Wrap a tab

You can wrap a tab in other presentational components. In this example we have added a tooltip to each tab.

Example image of tabs being wrapped

1
2
const TabWrappingExample = () => {
  return (
    <Tabs id="tabs-wrapping">
      <TabList>
        <Tooltip content="Tooltip for tab 1">
          <Tab>Tab 1</Tab>
        </Tooltip>
        <Tooltip content="Tooltip for tab 2">
          <Tab>Tab 2</Tab>
        </Tooltip>
        <Tooltip content="Tooltip for tab 3">
          <Tab>Tab 3</Tab>
        </Tooltip>
      </TabList>
      <TabPanel>
        <Box padding="space.300">
          This is the content area of the first tab.
        </Box>
      </TabPanel>
      <TabPanel>
        <Box padding="space.300">
          This is the content area of the second tab.
        </Box>
      </TabPanel>
      <TabPanel>
        <Box padding="space.300">
          This is the content area of the third tab.
        </Box>
      </TabPanel>
    </Tabs>
  );
};

Rate this page: