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

TabView/TabPanel: Can't have TabPanels in a JSX fragment #5900

Closed
kabalan-datapostie opened this issue Feb 5, 2024 · 4 comments · Fixed by #5904
Closed

TabView/TabPanel: Can't have TabPanels in a JSX fragment #5900

kabalan-datapostie opened this issue Feb 5, 2024 · 4 comments · Fixed by #5904
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@kabalan-datapostie
Copy link

Describe the bug

Use case: want to conditionally render several TabPanels. To do this, the code would ideally look something like:

<TabView>
    <TabPanel header="Always here" />
    { myCondition && (<>
        <TabPanel header="Conditional panel 1" />
        <TabPanel header="Conditional panel 2" />
        <TabPanel header="Conditional panel 3" />
    </>) }
</TabView>

However in this case, the conditional panels don't show up, even when myCondition is true.

Reproducer

https://stackblitz.com/edit/vitejs-vite-gyvk7d?file=src%2FApp.tsx

PrimeReact version

10.4.0

React version

18.x

Language

ALL

Build / Runtime

Next.js

Browser(s)

Chrome 121

Steps to reproduce the behavior

See reproducer (can reproduce in Vite but also other builds / runtimes)

Expected behavior

TabPanels should show

@kabalan-datapostie kabalan-datapostie added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 5, 2024
@kabalan-datapostie
Copy link
Author

Of course, a workaround is to do

{ myCondition && (<TabPanel header="Conditional panel 1" />)}
{ myCondition && (<TabPanel header="Conditional panel 2" />)}
{ myCondition && (<TabPanel header="Conditional panel 3" />)}

but this is not good practice and can quickly become difficult to maintain.

@melloware
Copy link
Member

melloware commented Feb 5, 2024

TabPanel should have a visible property so you can do this.

<TabPanel header="Conditional panel 1" visible={myCondition} />

@melloware melloware added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 5, 2024
melloware added a commit to melloware/primereact that referenced this issue Feb 5, 2024
@melloware melloware self-assigned this Feb 5, 2024
@melloware melloware added this to the 10.5.0 milestone Feb 5, 2024
@kabalan-datapostie
Copy link
Author

Thanks @melloware ! I suppose that's pretty much the same as the workaround as we'd have to copy-paste myCondition several times, but it's a minor issue.

@melloware
Copy link
Member

yeah it makes to me more readable code though and we have visible in other repeating components like MenuItem etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants