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

[Feature Request] Add destroyInactiveTabPanel prop for Tabs component #1562

Closed
u3u opened this issue Sep 3, 2023 · 7 comments · Fixed by #2973
Closed

[Feature Request] Add destroyInactiveTabPanel prop for Tabs component #1562

u3u opened this issue Sep 3, 2023 · 7 comments · Fixed by #2973
Assignees
Labels
🔦 Type: Feature New feature or request
Milestone

Comments

@u3u
Copy link
Contributor

u3u commented Sep 3, 2023

Is your feature request related to a problem? Please describe.

In some cases, I hope that when switching tabs, the previous TabPanel will not be destroyed in order to preserve their state and avoid re-rendering.

Describe the solution you'd like

We can add a destroyInactiveTabPanel prop with a default value of false.
The inactive TabPanel can be hidden using display: none.
If the user wants to destroy the previous TabPanel every time they switch tabs, they can simply add it to the Tabs component.

Describe alternatives you've considered

Now can also achieve the same effect by yourself, but each time you need to write additional code or encapsulate it again.

const [selectedKey, setSelectedKey] = useState<TabKey>('basic');
const [canRenderTabs, setCanRenderTabs] = useState([selectedKey]);

const setSelectedTab = (key: TabKey) => {
  if (!canRenderTabs.includes(key)) setCanRenderTabs([...canRenderTabs, key]);
  setSelectedKey(key);
};

{canRenderTabs.map((key) => {
  const Content = tabsMap[key];
  const isSelected = key === selectedKey;

  return (
    <div className={twMerge(styles.panel, !isSelected && 'hidden')} key={key}>
      <Content />
    </div>
  );
})}

Screenshots or Videos

No response

@Softwaremanufaktur
Copy link
Contributor

when creating a brand new project with nextui 2.4.0 the property "destroyInactiveTabPanel" is not recognized (yet) :-/

// package.json
...
"dependencies": {
		"@nextui-org/react": "^2.4.0",
...

grafik

@wingkwong
Copy link
Member

@Softwaremanufaktur destroyInactiveTabPanel should be a prop for Tabs instead of Tab. The doc is incorrect. I'll update it.

@Neuro8
Copy link

Neuro8 commented May 30, 2024

Hi, I updated NextUI to 2.4.0 but the prop is not changing anything, my tab and the component within it keep being re rendered each time we switch tabs. Any idea why it could be the case?

I made sure to put the prop in Tabs as indicated above. And deleted Node_modules and reinstalled but the prop is still not working.

Thanks

@wingkwong
Copy link
Member

wingkwong commented May 30, 2024

@Neuro8 can u setup a minimal reproducible stackblitz project for us to investigate?

UPD: i can reproduce now. will take a look.

@drewdearing
Copy link

any update here? Setting destroyInactiveTabPanel to false does not prevent tab destruction.

@wingkwong
Copy link
Member

@drewdearing the fix has been deployed to 2.4.2. Are you using the latest version?

@drewdearing
Copy link

@drewdearing the fix has been deployed to 2.4.2. Are you using the latest version?

Oh I didn't realize there was a fix based on this thread. I'll give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔦 Type: Feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants