Skip to main content

Breaking: Tabs removed — use TabBar and useTabs

@trackunit/react-components 10.0.0 removes Tabs, TabList, Tab and TabContent, with no compatibility shim. If your app imports any of them, bumping to 10.0.0 is a compile failure until you migrate. Their replacement is useTabs with TabBar and TabPanels, and useRouterTabs from @trackunit/react-router-components for tabs whose selection lives in the URL.

A migration rewrites the usages it can prove equivalent and logs the rest for manual review. Run these two commands in the consuming repo:

npx nx g @trackunit/migrations:migrate
npx nx g @trackunit/migrations:run-migrations

Why this changed​

The new tabs are driven by data and use no React context. Each tab's value is written once, in items, and every other use is typed from it, so a misspelled value or a missing panel is a compile error instead of a panel that silently renders nothing. The bar is also quieter: tabs size to their content, and one underline slides to the selected tab.

When it affects you​

Nothing changes until you bump the package. From @trackunit/react-components 10.0.0:

// before
<Tabs onValueChange={setTab} value={tab}>
<TabList aria-label="Asset">
<Tab value="overview">Overview</Tab>
<Tab suffix={<Badge color="danger" count={count} />} value="alerts">Alerts</Tab>
<Tab disabled value="settings">Settings</Tab>
</TabList>
<TabContent value="overview"><Overview /></TabContent>
<TabContent value="alerts"><Alerts /></TabContent>
<TabContent value="settings">{settings}</TabContent>
</Tabs>

// after
const tabs = useTabs({
items: [
{ value: "overview", label: "Overview" },
{ value: "alerts", label: <>Alerts<Badge color="danger" count={count} /></> },
{ value: "settings", label: "Settings", disabled: true },
],
value: tab,
onValueChange: setTab,
});

<TabBar aria-label="Asset" tabs={tabs} {...tabs.keyboardProps} />
<TabPanels panels={{ overview: <Overview />, alerts: <Alerts />, settings }} tabs={tabs} />

Router-linked tabs (<Tab asChild> around a TanStack Router Link) become useRouterTabs:

const tabs = useRouterTabs({
items: [
{ value: "connected", label: "Connected", route: "/fleet/connected" },
{ value: "pending", label: "Pending", route: "/fleet/pending" },
],
});

<TabBar aria-label="Fleet" tabs={tabs} {...tabs.keyboardProps} />

Behaviour that changes with the new components:

  • Every TabBar needs a name, aria-label or aria-labelledby. It is a compile error without one.
  • Tab values are typed from items. A string state, prop or URL parameter that feeds value has to be narrowed to the tab values. tabs.parse(raw) narrows a raw string.
  • "No tab selected" is undefined, not "".
  • fullWidth is gone. Tabs size to their content.
  • Inactive panels unmount unless listed in keepMounted on TabPanels, which replaces forceMount.
  • onValueChange fires for keyboard moves too, and not when the selected tab is clicked again or opened in a new tab. Move analytics from onClick to onValueChange.
  • Tabs never take DOM focus. The tab list is the single tab stop and points at the selected tab with aria-activedescendant, so tests should assert focus on the tablist.
  • Disabled tabs use aria-disabled, not the disabled attribute, so tests should assert aria-disabled instead of toBeDisabled().
  • useRouterTabs selects the tab that owns the deepest matched route, and the first tab when no tab's route matches. Clicks push a history entry and arrow keys replace it.

What the migration does​

The package includes the @trackunit/react-components:v10-0-0-tabs-to-tabbar migration:

  • It turns each Tab into an item of useTabs({ items }), with the children as label and a suffix folded in after them, and moves value/onValueChange or defaultValue to useTabs. TabList becomes TabBar, and the TabContents become the panels of one TabPanels.
  • It narrows a useState<string> that feeds value to the tab values, and turns an empty-string "no selection" into undefined.
  • It rewrites router-linked tabs to useRouterTabs only when the old selection provably picks the same tab. When it can't prove that, it leaves the file as it was and logs a suggested useRouterTabs block for you to apply.
  • It adds @trackunit/react-router-components to your package.json when a file now uses useRouterTabs.

It leaves these untouched and logs the reason for manual review:

  • a TabBar it can't name: it only derives aria-label from a single translated heading next to the tabs
  • values typed as string from props or URL parameters
  • onClick on a Tab or its Link
  • Link props other than to and data-testid, such as search, params set by hand, activeProps or a spread
  • router tabs selected by pathname, location, matchRoute, props or helpers
  • forceMount, nested Tabs, mapped or conditional router tabs, and a Tabs split from its TabList

The migration doesn't format what it writes: run Prettier on the changed files afterwards. A second run changes nothing.

See the TabBar docs and the useRouterTabs docs for the full API. For the complete update process, see Maintaining Your Application.