Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: Tab Component Clearing Redux and Component State on Tab Swit #3315

Open
rahul-crossml opened this issue Jan 9, 2025 · 4 comments

Comments

@rahul-crossml
Copy link

I encountered an issue with the ShadCN Tab component where switching between tabs clears both component state and Redux state. This occurs because the inactive tab content appears to be unmounted when switching tabs.

@FredrikMWold
Copy link

This is expected behavior Radix Tabs only mount the active content container. When a React component unmounts, its internal state is lost.

Could it be that your Redux provider is mounted inside Tabs.Content instead of at the root of your app? That would explain why the store is being cleared.

@Fengjing95
Copy link

How can I keep the original DOM structure when the tab is not selected? I don't see any relevant instructions in the API.

@FredrikMWold
Copy link

You could try force-mounting the Tabs.Content and conditionally applying display: none. That way, the content stays in the DOM but remains hidden when needed.

@Fengjing95
Copy link

You could try force-mounting the Tabs.Content and conditionally applying display: none. That way, the content stays in the DOM but remains hidden when needed.

Thank you. I also found a solution that can be achieved.

<TabsContent
   // ......
    forceMount
    hidden={item.id !== activeTermId}
  >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants