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 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>
)
}
| Prop | Values | Default | Meaning |
|---|---|---|---|
variant | 'primary' | 'secondary' | 'primary' | Which anatomy the row uses |
scrollable | boolean | false | Natural tab widths with horizontal scroll, instead of an equal split |
edgePadding | number | 52 | Padding before the first and after the last tab. Scrollable rows only |
showDivider | boolean | true | The 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
| Prop | Target |
|---|---|
containerColor | The row background |
contentColor | The label and icon color of the inactive tabs |
selectedContentColor | The label and icon color of the active tab. The state layers derive from it |
indicatorColor | The active indicator |
labelStyle | The label Text of every tab. It doesn't affect the icons |
style | The 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
| Token | Primary | Secondary |
|---|---|---|
| Container | surface, elevation 0, square corners | surface, elevation 0, square corners |
| Height | 48dp, 64dp with an icon above the label | 48dp |
| Label | titleSmall; active primary, inactive onSurfaceVariant | titleSmall; active onSurface, inactive onSurfaceVariant |
| Icon | 24dp, the same colors as the label | 24dp, the same colors as the label |
| Indicator | primary, 3dp, matched to the content of the tab | primary, 2dp, full tab width |
| Padding | 16dp horizontal per tab | 16dp horizontal per tab |
| Divider | 1dp outlineVariant along the bottom | 1dp 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 tabrole="tab"withaccessibilityState.selected. PassaccessibilityLabelto name the row itself ("Sections", "Library"). - The screen-reader name of a tab falls back to its label. Set
accessibilityLabelon the item for an icon-only tab. - A disabled tab exposes
accessibilityState.disabledand 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-controlsyourself if you render panels that need it.
Props
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
items | TabItem[] | - | Yes | The tabs to render. |
value | string | - | No | Value of the active tab (controlled). |
defaultValue | string | - | No | Value of the initially active tab (uncontrolled). Defaults to the first item — a tab row with nothing active reads as broken. |
onValueChange | (value: string) => void | - | No | Called with the value of the tab that was pressed. |
position | SharedValue<number> | - | No | The 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. |
variant | enum | primary | No | Tab anatomy. |
scrollable | boolean | | No | Lay 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. |
edgePadding | number | 52 | No | Padding before the first and after the last tab, in dp. Scrollable rows only — a fixed row divides the full width between its tabs. |
showDivider | boolean | | No | Whether the 1dp divider is drawn along the bottom of the row. |
containerColor | string | surface | No | Override the row background. |
contentColor | string | onSurfaceVariant | No | Override the label and icon color of inactive tabs. |
selectedContentColor | string | primary (primary variant) / onSurface (secondary variant) | No | Override the label and icon color of the active tab. State-layer colors are derived from it automatically. |
indicatorColor | string | primary | No | Override the active indicator color. |
labelStyle | StyleProp<TextStyle> | - | No | Style applied to every tab's label `Text` — does not affect the icons. |
style | StyleProp<ViewStyle> | - | No | Style applied to the row container. |
accessibilityLabel | string | - | No | Screen-reader label for the tab row itself. |
testID | string | - | No | Test id applied to the row container. |