Skip to content
Stylhero 0.6.2
React Native

Theme

Core

Feedback

Inputs

Navigation

Overlays

React Native / Navigation

Tabs

A row of tabs with an underline on the selected one, and the selected tab's content below. Use it for sections of one screen; for two to five views of the same content, SegmentedControl is lighter. Tabs say their position ("tab, 2 of 4"); a scrollable bar keeps the selected tab in view.

import { Tabs } from "@stylhero/native";

Example

import { useState } from "react";
import { Tabs, Text } from "@stylhero/native";

function TabsExample() {
  const [tab, setTab] = useState<"parts" | "benchmarks">("parts");
  return (
    <Tabs
      accessibilityLabel="Build details"
      value={tab}
      onChange={setTab}
      tabs={[
        { value: "parts", label: "Parts", content: <Text>8 parts</Text> },
        { value: "benchmarks", label: "Benchmarks", content: <Text>About 140 FPS at 1440p</Text> },
      ]}
    />
  );
}

Props

PropTypeDefaultDescription
onChange required (value: T) => void -
tabs required TabItem<T>[] -
value required T -
accessibilityLabel string - Names the tab bar for screen readers, e.g. "Build sections".
keepMounted boolean - Keep every tab's content mounted (hidden when not selected), e.g. to keep scroll position or form input.
scrollable boolean tabs.length > 3 Let the bar scroll sideways instead of sharing the width equally. Default true with more than three tabs. Labels never shrink or wrap when scrolling.
style StyleProp<ViewStyle> -
testID string -

Types

type TabItem<T extends string> = {
  value: T;
  label: string;
  /** Shown under the tab bar while this tab is selected. Leave it out to use the bar alone. */
  content?: ReactNode;
  disabled?: boolean;
};

Screen reader gestures

Gesture (VoiceOver / TalkBack)Does
Double-tap a tabSelects it and shows its content

Accessibility

  • A tab list named by accessibilityLabel; each tab says it's selected and its position ("tab, 2 of 4").
  • Content of other tabs isn't in the screen reader's path, even with keepMounted.

Generated from src/components/Tabs.tsx. Something wrong or missing? Open an issue.