Skip to main content

Tabs

Tabs organize content into groups that the user switches between without a change of screen. It follows the Material Design 3 Tabs specification.

There are two variants. Primary tabs sit directly under an app bar and mark the active tab with a short indicator, matched to its label. Secondary tabs sit inside content, often under a primary row, and mark the active tab with a full-width indicator.

Tabs is a bar, not a navigator

Tabs renders the row and tells you which tab the user pressed. It doesn't own screens, mount panels, or integrate with a navigator. Point it at whatever you already use: useState for a panel on one screen, or the state of your router for real routes. See Wiring it to a navigator.

Usage​

Pass the tabs as items and read the selection from onValueChange. With no value prop, Tabs keeps the active tab itself and starts on the first item.

import { Tabs } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useState } from 'react'
import { Text, View } from 'react-native'

const SECTIONS = [
{ value: 'flights', label: 'Flights' },
{ value: 'trips', label: 'Trips' },
{ value: 'explore', label: 'Explore' },
]

const PANELS = {
flights: 'Two seats left at this price.',
trips: 'Nothing booked yet.',
explore: 'Places you might like.',
}

function Screen() {
const [section, setSection] = useState('flights')
return (
<View style={{ flex: 1 }}>
<Tabs items={SECTIONS} value={section} onValueChange={setSection} />
<View style={{ padding: 24 }}>
<Text>{PANELS[section]}</Text>
</View>
</View>
)
}

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<Screen />
</ThemeProvider>
</SafeAreaProvider>
)
}

Variants​

import { Tabs } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

const TRAVEL = [
{ value: 'flights', label: 'Flights', icon: 'airplane' },
{ value: 'hotels', label: 'Hotels', icon: 'bed-outline' },
{ value: 'cars', label: 'Cars', icon: 'car-outline' },
]

const MANY = [
{ value: 'overview', label: 'Overview' },
{ value: 'specifications', label: 'Specifications' },
{ value: 'reviews', label: 'Reviews' },
{ value: 'questions', label: 'Questions' },
{ value: 'shipping', label: 'Shipping' },
]

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, gap: 24, paddingTop: 24 }}>
{/* Primary: icon above the label, 64dp tall */}
<Tabs items={TRAVEL} />
{/* Secondary: icon inline, 48dp, full-width indicator */}
<Tabs variant="secondary" items={TRAVEL} />
{/* Scrollable: natural widths, active tab scrolled into view */}
<Tabs scrollable items={MANY} defaultValue="reviews" />
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}
PropValuesDefaultMeaning
variant'primary' | 'secondary''primary'Which anatomy the row uses
scrollablebooleanfalseNatural tab widths with horizontal scroll, instead of an equal split
edgePaddingnumber52Padding before the first and after the last tab. Scrollable rows only
showDividerbooleantrueThe 1dp divider along the bottom of the row

A fixed row divides its width equally between the tabs, so a long label truncates to one line. Use scrollable past four tabs, or when the labels are long enough to truncate. A scrollable tab takes its natural width, with a floor of 90dp.

An icon changes the anatomy per variant. A primary tab stacks it above the label and grows to 64dp. A secondary tab puts it before the label and stays 48dp.

Selection​

value + onValueChange is the controlled form. Leave value off, and the row keeps the selection itself, from defaultValue or the first item. A tab row with nothing active looks broken, and that is why there is no "no selection" state.

{/* Controlled — the row shows what your state says */}
<Tabs items={items} value={section} onValueChange={setSection} />

{/* Uncontrolled — the row remembers, and tells you */}
<Tabs items={items} defaultValue="trips" onValueChange={load} />

onValueChange fires on every press, controlled or not.

Wiring it to a navigator​

Tabs stops at the bar on purpose. With expo-router, drive it from the current route:

import { Tabs } from '@rootnative/components'
import { usePathname, useRouter } from 'expo-router'

const SECTIONS = [
{ value: '/library/albums', label: 'Albums' },
{ value: '/library/artists', label: 'Artists' },
]

function LibraryTabs() {
const pathname = usePathname()
const router = useRouter()

return (
<Tabs
items={SECTIONS}
value={SECTIONS.find((s) => pathname.startsWith(s.value))?.value}
onValueChange={(value) => router.replace(value)}
/>
)
}

The same shape works for react-navigation (useNavigationState + navigation.navigate), or for no navigator at all: a useState and a conditional render.

Following a pager​

Above a swipe pager, pass the page position as position. The indicator then moves with the finger between the two tabs on each side of it, in items order. The value is the page index plus the fraction of the swipe toward the next page, on the UI thread. With react-native-pager-view, write it from the Reanimated onPageScroll handler, so the indicator doesn't lag behind the finger when the JS thread is busy:

import { Tabs } from '@rootnative/components'
import { useMotionValue } from '@rootnative/inertia'
import { Animated } from '@rootnative/inertia/reanimated'
import { useRef, useState } from 'react'
import PagerView, {
type PagerViewOnPageScrollEvent,
} from 'react-native-pager-view'
import { useEvent } from 'react-native-reanimated'

const AnimatedPager = Animated.createAnimatedComponent(PagerView)

function CategoryPager() {
const pager = useRef<PagerView>(null)
const [value, setValue] = useState(CATEGORIES[0].value)
const position = useMotionValue(0)
const onPageScroll = useEvent<PagerViewOnPageScrollEvent>(
(event) => {
'worklet'
position.value = event.position + event.offset
},
['onPageScroll'],
)

return (
<>
<Tabs
items={CATEGORIES}
scrollable
value={value}
position={position}
onValueChange={(next) => {
pager.current?.setPage(CATEGORIES.findIndex((c) => c.value === next))
}}
/>
<AnimatedPager
ref={pager}
style={{ flex: 1 }}
onPageScroll={onPageScroll}
onPageSelected={(e) => setValue(CATEGORIES[e.nativeEvent.position].value)}
>
{CATEGORIES.map((c) => (
<CategoryPage key={c.value} category={c.value} />
))}
</AnimatedPager>
</>
)
}

Keep value in sync from onPageSelected. It still drives the active tab colors, and it scrolls a scrollable row to the selected tab when the swipe ends. The row doesn't scroll with the finger. position takes a Reanimated shared value only. It doesn't accept a React Native Animated node, such as the position of react-native-tab-view.

The indicator​

The component places the indicator from measured geometry, not from a flex rule. A primary indicator matches the width of the content of the tab (the label, or the icon-and-label column when an icon stacks above it), not the width of the tab. The floor is 24dp, so a one-character label still gets something to see. A secondary indicator spans the whole tab.

The indicator stays unmounted until the active tab reports a layout, so it appears in place. It doesn't slide in from the leading edge of the row on the first render. After that, both its offset and its width ride springDefaultSpatial, and under reduced motion they go to their end values at once; see Motion. With a pager position, the indicator follows the finger instead, and reduced motion doesn't gate it: that is the swipe, not an animation.

On a scrollable row, a tab that is partly off screen scrolls into view when you select it, centred where there is room to centre it.

Overrides​

PropTarget
containerColorThe row background
contentColorThe label and icon color of the inactive tabs
selectedContentColorThe label and icon color of the active tab. The state layers derive from it
indicatorColorThe active indicator
labelStyleThe label Text of every tab. It doesn't affect the icons
styleThe row container

A disabled tab always uses the MD3 disabled treatment (38% content). No override changes that.

When you pass testID, the indicator and the divider carry <testID>-indicator and <testID>-divider, so a test can assert on them.

Tokens​

TokenPrimarySecondary
Containersurface, elevation 0, square cornerssurface, elevation 0, square corners
Height48dp, 64dp with an icon above the label48dp
LabeltitleSmall; active primary, inactive onSurfaceVarianttitleSmall; active onSurface, inactive onSurfaceVariant
Icon24dp, the same colors as the label24dp, the same colors as the label
Indicatorprimary, 3dp, matched to the content of the tabprimary, 2dp, full tab width
Padding16dp horizontal per tab16dp horizontal per tab
Divider1dp outlineVariant along the bottom1dp outlineVariant along the bottom

Two values differ from androidx. The secondary indicator is 2dp, as the spec says, where Compose falls back to the 3dp of the primary token, because SecondaryNavigationTabTokens declares no indicator. An icon-and-label tab is 64dp, as IconAndLabelTextContainerHeight says, where the Compose Tab still uses a legacy 72dp.

Accessibility​

  • The row reports role="tablist", and each tab role="tab" with accessibilityState.selected. Pass accessibilityLabel to name the row itself ("Sections", "Library").
  • The screen-reader name of a tab falls back to its label. Set accessibilityLabel on the item for an icon-only tab.
  • A disabled tab exposes accessibilityState.disabled and stops responding.
  • On the web, a tab shows a keyboard focus ring (secondary, 3dp), driven by the same focus-visible state as the rest of the library.
  • Tabs owns no panels, so you add aria-controls yourself if you render panels that need it.

Props​

PropTypeDefaultRequiredDescription
itemsTabItem[]-YesThe tabs to render.
valuestring-NoValue of the active tab (controlled).
defaultValuestring-NoValue of the initially active tab (uncontrolled). Defaults to the first item — a tab row with nothing active reads as broken.
onValueChange(value: string) => void-NoCalled with the value of the tab that was pressed.
positionSharedValue<number>-NoThe page position of a pager under the row, as the index of the page plus the fraction of the swipe toward the next one, on the UI thread. When set, the indicator moves with the finger between the tabs on each side of the position, in `items` order, instead of springing to the active tab when `value` changes. Keep `value` in sync from the pager's page-selected event: it still drives the active tab colors, and it scrolls a scrollable row to the selected tab. Pass a Reanimated shared value written from the pager's UI-thread scroll handler; a value written from the JS thread lags behind the finger under load.
variantenumprimaryNoTab anatomy.
scrollablebooleanNoLay the tabs out at their natural width and scroll horizontally, instead of dividing the row equally between them. Reach for it past four tabs, or when the labels are long enough to truncate.
edgePaddingnumber52NoPadding before the first and after the last tab, in dp. Scrollable rows only — a fixed row divides the full width between its tabs.
showDividerbooleanNoWhether the 1dp divider is drawn along the bottom of the row.
containerColorstringsurfaceNoOverride the row background.
contentColorstringonSurfaceVariantNoOverride the label and icon color of inactive tabs.
selectedContentColorstringprimary (primary variant) / onSurface (secondary variant)NoOverride the label and icon color of the active tab. State-layer colors are derived from it automatically.
indicatorColorstringprimaryNoOverride the active indicator color.
labelStyleStyleProp<TextStyle>-NoStyle applied to every tab's label `Text` — does not affect the icons.
styleStyleProp<ViewStyle>-NoStyle applied to the row container.
accessibilityLabelstring-NoScreen-reader label for the tab row itself.
testIDstring-NoTest id applied to the row container.