Tabs

The Tabs component set is a collection of accessible, themeable, and responsive components to create a tabbed interface. The components include Tabs, TabList, TabPanel, TabPanels and Tab.

Import

import { Tabs, TabList, Tab, TabPanelList, TabPanel } from "@recastui/react";

Usage

Editable Example
<div className="container mx-auto p-6">
<Tabs>
<TabList>
<Tab>Tab 1</Tab>
<Tab>Tab 2</Tab>
<Tab>Tab 3</Tab>
</TabList>
<TabPanels className="p-2">
<TabPanel>
Content for Tab 1
</TabPanel>
<TabPanel>
Content for Tab 2
</TabPanel>
<TabPanel>
Content for Tab 3
</TabPanel>
</TabPanels>
</Tabs>
</div>

Orientation

Use the orientation prop to change the visual style of the Tabs. You can set the value to ‘horizontal’ or ‘vertical’. Default is ‘horizontal’.

Editable Example
<div className="container mx-auto p-6">
<Tabs orientation="vertical">
<TabList>
<Tab>Tab 1</Tab>
<Tab>Tab 2</Tab>
<Tab>Tab 3</Tab>
</TabList>
<TabPanels className="p-2">
<TabPanel>
Content for Tab 1
</TabPanel>
<TabPanel>
Content for Tab 2
</TabPanel>
<TabPanel>
Content for Tab 3
</TabPanel>
</TabPanels>
</Tabs>
</div>

Variant

Use the variant prop to change the variant style of the Tab component. You can set the value to ‘underline’, ‘outline’ or ‘pills’. Default is ‘underline’.

Editable Example
<div className="container mx-auto p-6">
<Tabs variant="outline">
<TabList>
<Tab>Tab 1</Tab>
<Tab>Tab 2</Tab>
<Tab>Tab 3</Tab>
</TabList>
<TabPanels className="p-2">
<TabPanel>
Content for Tab 1
</TabPanel>
<TabPanel>
Content for Tab 2
</TabPanel>
<TabPanel>
Content for Tab 3
</TabPanel>
</TabPanels>
</Tabs>
</div>

Rounded

Use the rounded prop to add rounded corners for the Tab component. There are 5 rounded options: none, sm, md, lg, full. Default is none

Editable Example
<div className="container mx-auto p-6">
<Tabs variant="pills" rounded="full">
<TabList>
<Tab>Tab 1</Tab>
<Tab>Tab 2</Tab>
<Tab>Tab 3</Tab>
</TabList>
<TabPanels className="p-2">
<TabPanel>
Content for Tab 1
</TabPanel>
<TabPanel>
Content for Tab 2
</TabPanel>
<TabPanel>
Content for Tab 3
</TabPanel>
</TabPanels>
</Tabs>
</div>

Props

Tabs

PropTypeDefaultDescription
childrenReact.ReactNodeThe child components to be rendered within the Tabs.
defaultIndexnumber0The initial active tab index.
orientation‘vertical’‘horizontal’‘horizontal’
variant‘underline’|‘outline’|‘pills’‘outline’Tabs orientation layout.
rounded‘none’|‘sm’|‘md’‘lg’|‘full’‘none’
onTabChange(index: number) => voidCallback function to be invoked when the active tab is changed.

TabList

PropTypeDefaultDescription
classNamestringCustom className for the tab.
childrenReact.ReactNodeThe Tab components to be rendered.

Tab

PropTypeDefaultDescription
classNamestringCustom className for the tab.
childrenReact.ReactNodeThe content of the tab.
disabledbooleanDisable the Tab from being selected.

TabPanels

PropTypeDefaultDescription
classNamestringCustom className for the tab.
childrenReact.ReactNodeThe TabPanel components to be rendered.

TabPanel

PropTypeDefaultDescription
classNamestringCustom className for the tab panel.
childrenReact.ReactNodeThe content of the tab panel.

Accessibility

The Tabs components are built with accessibility in mind, following the WAI-ARIA standards for tab components. The components include keyboard navigation, proper focus management, and the required ARIA roles and attributes.

Keyboard Navigation

The Tabs components support the following keyboard interactions:

ArrowRight or ArrowDown: Moves focus to the next tab. If the focus is on the last tab, it moves the focus to the first tab.

ArrowLeft or ArrowUp: Moves focus to the previous tab. If the focus is on the first tab, it moves the focus to the last tab.

Theming

The Tabs components use CVA variants and Tailwind CSS for theming. You can customize the appearance of the components by modifying the className prop or adding custom styles to your project.

Previous
Switch