reactjs / reactjs/react-tabs

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

Open
#344 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.1k
Forks
455
Avg merge
5h 9m
Merged PRs (30d)
2

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the DndProvider, Tabs, TabList, and TabPanel structure, then inspect how the warning counts Tab and TabPanel elements. Done means a provider-first composition renders without the warning while retaining equal Tab and TabPanel elements.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.