Tabs

PreviousNext

A set of layered sections of content—known as tab panels—that are displayed one at a time.

Installation

pnpm dlx bna-ui add tabs

Usage

import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs';
<Tabs defaultValue='tab1'>
  <TabsList>
    <TabsTrigger value='tab1'>Tab 1</TabsTrigger>
    <TabsTrigger value='tab2'>Tab 2</TabsTrigger>
    <TabsTrigger value='tab3'>Tab 3</TabsTrigger>
  </TabsList>
  <TabsContent value='tab1'>
    <Text>Content for Tab 1</Text>
  </TabsContent>
  <TabsContent value='tab2'>
    <Text>Content for Tab 2</Text>
  </TabsContent>
  <TabsContent value='tab3'>
    <Text>Content for Tab 3</Text>
  </TabsContent>
</Tabs>

Examples

Default

Vertical Orientation

Disabled Tabs

Custom Styling

API Reference

Tabs

The root container for the tabs component.

PropTypeDefaultDescription
hapticbooleantrueWhether to trigger haptic feedback when the active tab changes, by tap or by swipe. Programmatic changes stay silent.
childrenReactNode-The tabs list and content components.
defaultValuestring-The value of the tab that should be active by default.
valuestring-The controlled active tab value. When provided, the component becomes controlled and onValueChange must be used to update it.
onValueChange(value: string) => void-Called whenever the active tab changes, whether by press or swipe.
orientation'horizontal' | 'vertical''horizontal'The orientation of the tabs.
enableSwipebooleantrueWhether horizontal tabs can be swiped between, in addition to pressing a trigger. Has no effect when orientation is "vertical".
styleViewStyle-Additional styles to apply to the container.

TabsList

Container for the tab triggers.

PropTypeDescription
childrenReactNodeThe tab trigger components.
styleViewStyleAdditional styles to apply to the tabs list.

TabsTrigger

The clickable tab that activates its associated content.

PropTypeDefaultDescription
childrenReactNode-The content of the tab trigger (usually text).
valuestring-The unique value that identifies this tab.
disabledbooleanfalseWhether the tab is disabled.
styleViewStyle-Additional styles to apply to the trigger.
textStyleTextStyle-Additional styles to apply to the trigger text.

TabsContent

The content panel associated with a tab trigger.

PropTypeDescription
childrenReactNodeThe content to display when the tab is active.
valuestringThe value that matches the associated trigger.
styleViewStyleAdditional styles to apply to the content.

Accessibility

The Tabs component is built with accessibility in mind:

  • TabsList exposes accessibilityRole="tablist", each TabsTrigger exposes accessibilityRole="tab" with accessibilityState={{ selected, disabled }}
  • Disabled tabs report accessibilityState.disabled to screen readers