question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to specify unmountOnExit for TabPanel or Tabs

See original GitHub issue

Currently, tab content will unmount upon switching to another tab. That can remain the default. It would be great however to be able to specify for tab to “stay alive” when it’s no longer the active tab. Could be done at tab level, or if it’s too difficult, ad the Tabs level (i.e. the behaviour will apply to all tabs). Understandably there is a performance implication, hence by default this behaviour should not be enabled.

Summary 💡

per tab

<TabPanel value={value} index="one" unmountOnExit={false}>
    Item One
 </TabPanel>
<TabPanel value={value} index="two">
    Item Two
</TabPanel>

if too difficult – for all tabs

<Tabs value={value} onChange={handleChange} unmountOnExit={false} aria-label="wrapped label tabs example">
</Tabs>
<TabPanel value={value} index="one">
    Item One
</TabPanel>
<TabPanel value={value} index="two">
    Item Two
</TabPanel>

Motivation 🔦

I have tabs with fairly small amount of content. I would like them to maintain self-contained state. That state will be lost upon unmount. The solution is fairly simple to keep the state elsewhere, OR, have an option to simply not have the component unmount …

Thanks!!!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
clearwaterstreamcommented, Oct 2, 2020

@eps1lon Thank for following up. Apologies, after reading your comment I realize may not be using the right terminology. Indeed in the samples TabPanel is a div with a hidden flag.

Let me better describe the problem:

What I find odd is that if I use Collapse or Accordion, the content in each of the accordion cards “survives” the expand / collapse cycle. When using Tabs, if I’m using the state hook for anything within the TabPanel, the state resets when I jump off and back into any particular tab. It’s as if the tab is getting created anew and the useState hook is not doing what it’s supposed to.

I’ll compile an example with Accordion and same one with Tabs to demonstrate the behaviour difference … if I can’g repro then it’s something on my end and I’ll just close the issue.

0reactions
nico-hernandezcommented, May 2, 2022

@oliviertassinari yes #21250 describes my issue perfectly – “Lost states between different panels (by keeping the panels mounted)”

Not sure why I did not find it in open issues, I think I was searching for tabs and unmountOnExit

Did you get any solution or workaround? I think we are in the same boat, I’m trying to replicate Accordion behaviour (unmount=false) in Tabs but I wasn’t successful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow to specify unmountOnExit for TabPanel or Tabs #22840
Tab panels using @material-ui/core are fully controlled by the user. Our demo uses hidden instead of unmounting which means they stay hidden.
Read more >
React recreates my component on each material ui tab switch
This is the expected behaviour for a component. Before it gets mounted, the constructor gets called. It might be worth giving the docs...
Read more >
Tab components - React-Bootstrap
Tabs is a higher-level component for quickly creating a Nav matched with a set of TabPane s. Home; Profile; Contact.
Read more >
Tabs - React-Bootstrap
Togglable tabs Tabs, Tab, TabContainer, TabContent, TabPane. Add quick, dynamic tab functionality to transition through panes of local content. #Uncontrolled.
Read more >
Tabs API - Material UI - MUI
Name Type Default action ref allowScrollButtonsMobile bool false aria‑label string
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found