# Tabs **Category**: native **URL**: https://www.heroui.com/docs/native/components/tabs **Source**: https://raw.githubusercontent.com/heroui-inc/heroui/refs/heads/v3/apps/docs/content/docs/native/components/(navigation)/tabs.mdx > Organize content into tabbed views with animated transitions and indicators. *** ## Import ```tsx import { Tabs } from 'heroui-native'; ``` ## Anatomy ```tsx ... ... ... ``` - **Tabs**: Main container that manages tab state and selection. Controls active tab, handles value changes, and provides context to child components. - **Tabs.List**: Container for tab triggers. Groups triggers together with optional styling variants (primary or secondary). - **Tabs.ScrollView**: Optional scrollable wrapper for tab triggers. Enables horizontal scrolling when tabs overflow with automatic centering of active tab. - **Tabs.Trigger**: Interactive button for each tab. Handles press events to change active tab and measures its position for indicator animation. - **Tabs.Label**: Text content for tab triggers. Displays the tab title with appropriate styling. - **Tabs.Indicator**: Animated visual indicator for active tab. Smoothly transitions between tabs using spring or timing animations. - **Tabs.Separator**: Visual separator between tabs. Shows when the current tab value is not in the `betweenValues` array, with animated opacity transitions. - **Tabs.Content**: Container for tab panel content. Shows content when its value matches the active tab. ## Usage ### Basic Usage The Tabs component uses compound parts to create navigable content sections. ```tsx Tab 1 Tab 2 ... ... ``` ### Primary Variant Default rounded primary style for tab triggers. ```tsx Settings Profile ... ... ``` ### Secondary Variant Underline style indicator for a more minimal appearance. ```tsx Overview Analytics ... ... ``` ### Scrollable Tabs Handle many tabs with horizontal scrolling. ```tsx First Tab Second Tab Third Tab Fourth Tab Fifth Tab ... ... ... ... ... ``` ### Disabled Tabs Disable specific tabs to prevent interaction. ```tsx Active Disabled Another ... ... ``` ### With Icons Combine icons with labels for enhanced visual context. ```tsx Home Search ... ... ``` ### With Render Function Use a render function on `Tabs.Trigger` to access state and customize content based on selection. ```tsx {({ isSelected, value, isDisabled }) => ( Settings )} {({ isSelected }) => ( <> Profile )} ... ... ``` ### With Separators Add visual separators between tabs that show when the active tab is not between specified values. ```tsx General Notifications Profile ... ... ... ``` ## Example ```tsx import { Button, Checkbox, Description, ControlField, Label, Tabs, TextField, } from 'heroui-native'; import { useState } from 'react'; import { View, Text } from 'react-native'; import Animated, { FadeIn, FadeOut, LinearTransition, } from 'react-native-reanimated'; const AnimatedContentContainer = ({ children, }: { children: React.ReactNode; }) => ( {children} ); export default function TabsExample() { const [activeTab, setActiveTab] = useState('general'); const [showSidebar, setShowSidebar] = useState(true); const [accountActivity, setAccountActivity] = useState(true); const [name, setName] = useState(''); return ( General Notifications Profile Display the sidebar navigation panel Notifications about your account activity ); } ``` You can find more examples in the [GitHub repository](). ## API Reference ### Tabs | prop | type | default | description | | --------------- | ---------------------------- | ----------- | ----------------------------------------------------------------------------------------- | | `children` | `React.ReactNode` | - | Children elements to be rendered inside tabs | | `value` | `string` | - | Currently active tab value | | `variant` | `'primary' \| 'secondary'` | `'primary'` | Visual variant of the tabs | | `className` | `string` | - | Additional CSS classes for the container | | `animation` | `"disable-all" \| undefined` | `undefined` | Animation configuration. Use `"disable-all"` to disable all animations including children | | `onValueChange` | `(value: string) => void` | - | Callback when the active tab changes | | `...ViewProps` | `ViewProps` | - | All standard React Native View props are supported | ### Tabs.List | prop | type | default | description | | -------------- | ----------------- | ------- | -------------------------------------------------- | | `children` | `React.ReactNode` | - | Children elements to be rendered inside the list | | `className` | `string` | - | Additional CSS classes | | `...ViewProps` | `ViewProps` | - | All standard React Native View props are supported | ### Tabs.ScrollView | prop | type | default | description | | --------------------------- | ---------------------------------------- | ---------- | -------------------------------------------------------- | | `children` | `React.ReactNode` | - | Children elements to be rendered inside the scroll view | | `scrollAlign` | `'start' \| 'center' \| 'end' \| 'none'` | `'center'` | Scroll alignment variant for the selected item | | `className` | `string` | - | Additional CSS classes for the scroll view | | `contentContainerClassName` | `string` | - | Additional CSS classes for the content container | | `...ScrollViewProps` | `ScrollViewProps` | - | All standard React Native ScrollView props are supported | ### Tabs.Trigger | prop | type | default | description | | ------------------- | ------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------- | | `children` | `React.ReactNode \| ((props: TabsTriggerRenderProps) => React.ReactNode)` | - | Children elements to be rendered inside the trigger, or a render function | | `value` | `string` | - | The unique value identifying this tab | | `isDisabled` | `boolean` | `false` | Whether the trigger is disabled | | `className` | `string` | - | Additional CSS classes | | `...PressableProps` | `PressableProps` | - | All standard React Native Pressable props are supported | #### TabsTriggerRenderProps When using a render function for `children`, the following props are provided: | property | type | description | | ------------ | --------- | ------------------------------------------ | | `isSelected` | `boolean` | Whether this trigger is currently selected | | `value` | `string` | The value of the trigger | | `isDisabled` | `boolean` | Whether the trigger is disabled | ### Tabs.Label | prop | type | default | description | | -------------- | ----------------- | ------- | -------------------------------------------------- | | `children` | `React.ReactNode` | - | Text content to be rendered as label | | `className` | `string` | - | Additional CSS classes | | `...TextProps` | `TextProps` | - | All standard React Native Text props are supported | ### Tabs.Indicator | prop | type | default | description | | ----------------------- | ------------------------ | ------- | ------------------------------------------------------------ | | `children` | `React.ReactNode` | - | Custom indicator content | | `className` | `string` | - | Additional CSS classes | | `animation` | `TabsIndicatorAnimation` | - | Animation configuration | | `isAnimatedStyleActive` | `boolean` | `true` | Whether animated styles (react-native-reanimated) are active | | `...Animated.ViewProps` | `Animated.ViewProps` | - | All Reanimated Animated.View props are supported | #### TabsIndicatorAnimation Animation configuration for Tabs.Indicator component. Can be: - `false` or `"disabled"`: Disable all animations - `true` or `undefined`: Use default animations - `object`: Custom animation configuration | prop | type | default | description | | ------------------- | -------------------------------------- | ---------------------------------------------------------------------------- | ----------------------------------------------- | | `state` | `'disabled' \| boolean` | - | Disable animations while customizing properties | | `width.type` | `'spring' \| 'timing'` | `'spring'` | Type of animation to use | | `width.config` | `WithSpringConfig \| WithTimingConfig` | `{ stiffness: 1200, damping: 120 }` (spring) or `{ duration: 200 }` (timing) | Reanimated animation configuration | | `height.type` | `'spring' \| 'timing'` | `'spring'` | Type of animation to use | | `height.config` | `WithSpringConfig \| WithTimingConfig` | `{ stiffness: 1200, damping: 120 }` (spring) or `{ duration: 200 }` (timing) | Reanimated animation configuration | | `translateX.type` | `'spring' \| 'timing'` | `'spring'` | Type of animation to use | | `translateX.config` | `WithSpringConfig \| WithTimingConfig` | `{ stiffness: 1200, damping: 120 }` (spring) or `{ duration: 200 }` (timing) | Reanimated animation configuration | ### Tabs.Separator | prop | type | default | description | | ----------------------- | ------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | | `betweenValues` | `string[]` | - | Array of tab values between which the separator should be visible. The separator shows when the current tab value is NOT in this array | | `isAlwaysVisible` | `boolean` | `false` | If true, opacity is always 1 regardless of the current tab value | | `className` | `string` | - | Additional CSS classes | | `animation` | `TabsSeparatorAnimation` | - | Animation configuration | | `isAnimatedStyleActive` | `boolean` | `true` | Whether animated styles (react-native-reanimated) are active | | `children` | `React.ReactNode` | - | Custom separator content | | `...Animated.ViewProps` | `Animated.ViewProps` | - | All Reanimated Animated.View props are supported | **Note:** The following style properties are occupied by animations and cannot be set via className: - `opacity` - Animated for separator visibility transitions (0 when current tab is in `betweenValues`, 1 when not) To customize these properties, use the `animation` prop. To completely disable animated styles and use your own via className or style prop, set `isAnimatedStyleActive={false}`. #### TabsSeparatorAnimation Animation configuration for Tabs.Separator component. Can be: - `false` or `"disabled"`: Disable all animations - `true` or `undefined`: Use default animations - `object`: Custom animation configuration | prop | type | default | description | | ---------------------- | ----------------------- | ------------------- | ----------------------------------------------- | | `state` | `'disabled' \| boolean` | - | Disable animations while customizing properties | | `opacity.value` | `[number, number]` | `[0, 1]` | Opacity values [hidden, visible] | | `opacity.timingConfig` | `WithTimingConfig` | `{ duration: 200 }` | Animation timing configuration | ### Tabs.Content | prop | type | default | description | | -------------- | ----------------- | ------- | --------------------------------------------------- | | `children` | `React.ReactNode` | - | Children elements to be rendered inside the content | | `value` | `string` | - | The value of the tab this content belongs to | | `className` | `string` | - | Additional CSS classes | | `...ViewProps` | `ViewProps` | - | All standard React Native View props are supported | ## Hooks ### useTabs Hook to access tabs root context values within custom components or compound components. ```tsx import { useTabs } from 'heroui-native'; const CustomComponent = () => { const { value, onValueChange, nativeID } = useTabs(); // ... your implementation }; ``` **Returns:** `UseTabsReturn` | property | type | description | | --------------- | ------------------------- | ------------------------------------------ | | `value` | `string` | Currently active tab value | | `onValueChange` | `(value: string) => void` | Callback function to change the active tab | | `nativeID` | `string` | Unique identifier for the tabs instance | **Note:** This hook must be used within a `Tabs` component. It will throw an error if called outside of the tabs context. ### useTabsMeasurements Hook to access tab measurements context values for managing tab trigger positions and dimensions. ```tsx import { useTabsMeasurements } from 'heroui-native'; const CustomIndicator = () => { const { measurements, variant } = useTabsMeasurements(); // ... your implementation }; ``` **Returns:** `UseTabsMeasurementsReturn` | property | type | description | | ----------------- | ------------------------------------------------------- | ------------------------------------------------- | | `measurements` | `Record` | Record of measurements for each tab trigger | | `setMeasurements` | `(key: string, measurements: ItemMeasurements) => void` | Function to update measurements for a tab trigger | | `variant` | `'primary' \| 'secondary'` | Visual variant of the tabs | #### ItemMeasurements | property | type | description | | -------- | -------- | ----------------------------------- | | `width` | `number` | Width of the tab trigger in pixels | | `height` | `number` | Height of the tab trigger in pixels | | `x` | `number` | X position of the tab trigger | **Note:** This hook must be used within a `Tabs` component. It will throw an error if called outside of the tabs context. ### useTabsTrigger Hook to access tab trigger context values within custom components or compound components. ```tsx import { useTabsTrigger } from 'heroui-native'; const CustomLabel = () => { const { value, isSelected, nativeID } = useTabsTrigger(); // ... your implementation }; ``` **Returns:** `UseTabsTriggerReturn` | property | type | description | | ------------ | --------- | ------------------------------------------ | | `value` | `string` | The value of this trigger | | `nativeID` | `string` | Unique identifier for this trigger | | `isSelected` | `boolean` | Whether this trigger is currently selected | **Note:** This hook must be used within a `Tabs.Trigger` component. It will throw an error if called outside of the trigger context.