Skip to content

Radix UI Tabs Controlled Not Working — Fix Active Tab

DodaTech Updated 2026-06-24 1 min read

In this fix, you'll learn how to control Radix UI Tabs programmatically. This matters for tab navigation with sync, and appears in settings pages and profile sections.

The Problem

The following code demonstrates the typical mistake:

<Tabs defaultValue="account">
  <TabsList>
    <TabsTrigger value="account">Account</TabsTrigger>
    <TabsTrigger value="password">Password</TabsTrigger>
  </TabsList>
  <TabsContent value="account">Account settings</TabsContent>
  <TabsContent value="password">Password settings</TabsContent>
</Tabs>
// Works but can't programmatically change tabs

The Fix

Here is the corrected version:

const [tab, setTab] = useState('account');
<Tabs value={tab} onValueChange={setTab}>
  <TabsList>
    <TabsTrigger value="account">Account</TabsTrigger>
    <TabsTrigger value="password">Password</TabsTrigger>
  </TabsList>
  <TabsContent value="account">Account settings</TabsContent>
  <TabsContent value="password">Password settings</TabsContent>
</Tabs>
// Programmatically: setTab('password')
// Tab content switches programmatically

Prevention

  • Use value and onValueChange for controlled tabs.
  • Use defaultValue for uncontrolled tabs (initial state only).
  • The value string must match a TabsTrigger's value prop.
  • TabsContent with matching value renders when the tab is active.
  • Use URL search params to persist tab state across navigation.

Common Mistakes with ui tabs controlled

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world RADIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between defaultValue and value?

defaultValue sets the initial active tab for uncontrolled usage. value + onValueChange gives full control over the active tab. Use controlled for syncing with URL params or form state.

Can I disable a specific tab?

Yes — add disabled prop to TabsTrigger: <TabsTrigger value='coming-soon' disabled>. Disabled tabs can't be selected and appear grayed out.

How do I persist tab state in the URL?

Read the tab from URL search params: const [searchParams, setSearchParams] = useSearchParams(); const tab = searchParams.get('tab') || 'account'. Then onValueChange: (v) => setSearchParams({ tab: v }).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro