react-tabs icon indicating copy to clipboard operation
react-tabs copied to clipboard

State reset when switching tabs and forceRender render tabpanel on each tabpanel

Open TO19 opened this issue 7 years ago • 6 comments

Hello, Im trying to make an add / delete feature with react-tabs. Im able to delete and add. But when I switch tabs the state keep reseting. So I searched and find forceRender and forceRenderTabPanel. I tried both but when I use them every tabpanel is rendering in each tabpanel. I think there is a problem with my map or this is an issue. Here is a not working example:

https://codesandbox.io/s/late-http-epp5n?fontsize=14

When I use basic tabs without add and delete functions everything works fine.

TO19 avatar Jun 03 '19 01:06 TO19

Have you resolved this? I have the same issue and the forceRender props don't appear to have any affect.

richardpaynea55 avatar Aug 03 '20 13:08 richardpaynea55

I am also having the same issue.

dexsnake avatar Aug 04 '20 16:08 dexsnake

I managed to solve it by using the prop without using a Boolean value, so

<Tags ... forceRenderTabsPanel> ... </Tags>

Did the job.

richardpaynea55 avatar Aug 04 '20 16:08 richardpaynea55

I managed to solve it by using the prop without using a Boolean value, so

<Tags ... forceRenderTabsPanel> ... </Tags>

Did the job.

I tried this, how did you get past the issue of all the TabPanel's showing?

dexsnake avatar Aug 04 '20 17:08 dexsnake

That's a CSS issue, @DexSnake. If you forceRender panels, they will stay mounted in the DOM. You'll need to write some CSS to display only the selected tab. For the default classnames, this could look something like the following (taken from the default styles — https://github.com/reactjs/react-tabs/blob/25cfa16/style/react-tabs.css#L50-L56):

.react-tabs__tab-panel {
  display: none;
}

.react-tabs__tab-panel--selected {
  display: block;
}

Or, if you don't want to explicitly set the display property of the selected <TabPanel/>:

.react-tabs__tab-panel:not(.react-tabs__tab-panel--selected) {
  display: none;
}

joepvl avatar Aug 05 '20 11:08 joepvl

That's a CSS issue, @DexSnake. If you forceRender panels, they will stay mounted in the DOM. You'll need to write some CSS to display only the selected tab. For the default classnames, this could look something like the following (taken from the default styles — https://github.com/reactjs/react-tabs/blob/25cfa16/style/react-tabs.css#L50-L56):

.react-tabs__tab-panel {
  display: none;
}

.react-tabs__tab-panel--selected {
  display: block;
}

Or, if you don't want to explicitly set the display property of the selected <TabPanel/>:

.react-tabs__tab-panel:not(.react-tabs__tab-panel--selected) {
  display: none;
}

Ahhh, this makes sense. Thanks for the reply!

dexsnake avatar Aug 05 '20 12:08 dexsnake