-
I was surprised that non-active tabs still render the same as active tab. For non-trivial use-cases, like having some kind of data fetching + list rendering logic in tabs, we don't want to have it all mount when their tab is not active. So, instead of having to do something like this, where we need to control if content should be mounted, I think having a prop like Current example:import * as Tabs from "@radix-ui/react-tabs";
import {useState} from "react";
const activeTab = useState("tab1")
return (
<Tabs.Root
value={activeTab}
onValueChange={(newValue) => setActiveTab(newValue)}
>
<Tabs.List aria-label="tabs example">
<Tabs.Trigger value="tab1">One</Tabs.Trigger>
<Tabs.Trigger value="tab2">Two</Tabs.Trigger>
<Tabs.Trigger value="tab3">Three</Tabs.Trigger>
</Tabs.List>
{activeTab === "tab1" ? (
<Tabs.Content value="tab1">
Tab One
</Tabs.Content>
) : null }
{activeTab === "tab2" ? (
<Tabs.Content value="tab2">
Tab Two
</Tabs.Content>
) : null }
{activeTab === "tab3" ? (
<Tabs.Content value="tab3">
Tab Three
</Tabs.Content>
) : null }
</Tabs.Root>
) Proposed example:import * as Tabs from "@radix-ui/react-tabs";
return (
<Tabs.Root
defaultValue="tab1"
mountMode="active"
>
<Tabs.List aria-label="tabs example">
<Tabs.Trigger value="tab1">One</Tabs.Trigger>
<Tabs.Trigger value="tab2">Two</Tabs.Trigger>
<Tabs.Trigger value="tab3">Three</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="tab1">
Tab One
</Tabs.Content>
<Tabs.Content value="tab2">
Tab Two
</Tabs.Content>
<Tabs.Content value="tab3">
Tab Three
</Tabs.Content>
</Tabs.Root>
) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Related: #813 Hey @adokce thanks for your proposal. I think this makes a lot of sense and has been requested a few times recently. I can't see any strong reason why this shouldn't be the default behaviour. @jjenzz @benoitgrelard Are there any implications if we made this change? afaik none of our other primitives work this way out of the box so curious if there's a specific reason why we didn't go this route originally. |
Beta Was this translation helpful? Give feedback.
-
This has been added to 0.1.1-rc.6 |
Beta Was this translation helpful? Give feedback.
This has been added to 0.1.1-rc.6