Shadcn deletes Tab Content
Hey, i am working on a little project in next.js and wanted to use shadcn for my ui. I wanted to have two editor tabs and used the tab element for that. The problem is: If i select another tab and then switch back to the other tab it resets the code because shadcn deletes the inactive element
You can use the forceMount attribute on TabContent.
And don’t forget to set hidden
This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.
I had the same issue, if you don't have an array, you can do:
<TabsContent
value="tab-1"
forceMount
className="data-[state=inactive]:hidden"
>
...
</TabsContent>
<TabsContent
value="tab-2"
forceMount
className="data-[state=inactive]:hidden"
>
...
</TabsContent>