Next Chapter Begins 🚀Read the full story

Tabs

Tabs is a component that displays a list of tabs and allows the user to select one.

Code

Browse the source files, review the latest commits, and clone the repository to get started.

preview

Installation#

npx shadcn@latest add https://primereact.dev/r/tabs.json

Usage#

import { Tabs, TabsList, TabsTab, TabsPanels, TabsPanel } from '@/components/ui/tabs';
<Tabs>
    <TabsList>
        <TabsTab />
    </TabsList>
    <TabsPanels>
        <TabsPanel />
    </TabsPanels>
</Tabs>

Examples#

Basic#

Account Info

Update your personal information such as name, email address, and profile picture.

basic-demo

Dynamic#

Create tabs from an array to keep labels and panel content in sync.

Account Info

Update your personal information such as name, email address, and profile picture.

dynamic-demo

Controlled#

Control the active tab with value and onValueChange.

Account Info

Update your personal information such as name, email address, and profile picture.

controlled-demo

Scrollable#

Enable scrollable to navigate long tab lists with previous and next buttons.

Tab 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore.

scrollable-demo

Select on Focus#

Set selectOnFocus to activate tabs on focus.

Account Info

Update your personal information such as name, email address, and profile picture.

focus-selection-demo

Disabled#

Set disabled on TabsTab to prevent selection.

Account Info

Update your personal information such as name, email address, and profile picture.

disabled-demo

Template#

Use custom markup inside TabsTab and TabsPanel to build richer tab content.

Update your personal information such as name, email address, and profile picture.

template-demo

Accessibility#

Screen Reader#

TabsTab elements use the tab role and expose selected and disabled state via ARIA attributes. TabsPanel uses the tabpanel role and links back to its related tab with aria-labelledby.

Tab Keyboard Support#

KeyFunction
tabMoves focus to the active tab and then proceeds to the next focusable element.
enterActivates the focused tab header.
spaceActivates the focused tab header.
right arrowMoves focus to the next header. If focus is on the last header, moves focus to the first header.
left arrowMoves focus to the previous header. If focus is on the first header, moves focus to the last header.
homeMoves focus to the first header.
endMoves focus to the last header.