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

Tabs with context provider in between <Tabs> and <Tablist> #344

Open
anjalikk14 opened this issue Sep 11, 2020 · 0 comments
Open

Tabs with context provider in between <Tabs> and <Tablist> #344

anjalikk14 opened this issue Sep 11, 2020 · 0 comments

Comments

@anjalikk14
Copy link

Hi all,

I'm working on creating a drag and drop version of react tabs using react-dnd.

React dnd requires a DndProvider context to be wrapped around any draggable/droppable objects. I'm currently trying to do something like this:

function DndTabs({data}) {
  // (...Some functions that require the DndContext here...)
  return (
    <TabList>
      {Object.keys(data).map(tabId => {
        <Tab key={tabId}> tabId </Tab>
      })}
    </TabList>
  )
}

function DndContainer({data}) {
   return (
      <DndProvider> 
         <DndTabs data={data} />
      </DndProvider>
   )
}

function TabHolder() {
  return (
    <Tabs>
        <DndContainer data={data} />
        {Object.keys(data).map(tabId => {
          <TabPanel key={tabId}> tabId </TabPanel>
        })}
    </Tabs>
  )
}

This is throwing the
Warning: Failed prop type: There should be an equal number of 'Tab' and 'TabPanel' in 'UncontrolledTabs' error, even though the actual rendered HTML should have tablist and tabpanels as siblings with an equal number of Tab and TabPanel elements.

I tried following the advice in #253 (calling the react component as a function instead of letting react render it) but this causes issues with the DndContext because functions that require the context to exist need to render after the Context itself renders.

Is there any structure that I can use that will make this work, following the additional constraint that the Provider for the Dnd Context needs to appear/render before the actual Tabs?

@anjalikk14 anjalikk14 changed the title Tabs with separated tablist structure Tabs with context provider in between <Tabs> and <Tablist> Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant