blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Tab does not render inside a react fragment

Open zhiwang95 opened this issue 3 years ago • 3 comments

Environment

  • Package version(s): 3.42.0
  • Operating System: macOS Catalina Version 10.15.7 (19H15)
  • Browser name and version: Chrome Version 89.0.4389.90 (Official Build) (x86_64)

Code Sandbox

https://codesandbox.io/s/tab-issue-4u4kv?file=/src/App.js

Steps to reproduce

Check out the codesanbox example which renders a <Tab> component inside a react fragment.

Actual behavior

The <Tab> inside react fragment is not displayed.

Expected behavior

The <Tab> inside react fragment should be displayed.

zhiwang95 avatar Mar 30 '21 22:03 zhiwang95

Tabs expects Tab children only (the docs should do a better job of explaining this). What are you trying to accomplish by using a fragment?

adidahiya avatar Apr 07 '21 15:04 adidahiya

@adidahiya I ran into this same issue recently. A typical reason for a fragment is due to needing conditional sections, such as:

<Tabs>
  <Tab id="one" ... />
  <Tab id="two" ... />

  {isAdministrator && (
    <>
      <Tab id="three" ... />
      <Tab id="four" ... />
      ...
    </>
  )}
</Tabs>

Some workarounds would be to repeat the conditional, or to just render an array of Tab elements:

<Tabs>
  <Tab id="one" ... />
  <Tab id="two" ... />

  {isAdministrator && [
    <Tab key="three" id="three" ... />,
    <Tab key="four" id="four" ... />,
    ...
  ]}
</Tabs>

justinbhopper avatar Apr 16 '21 19:04 justinbhopper

@adidahiya ran into the same issue.

@justinbhopper Workaround worked for me though! (i.e. rendering the array of Tab elements.

colmex avatar May 03 '22 15:05 colmex