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

Dynamic Update of tabs doesn't open a tab by default #337

Open
DakkeOG opened this issue Jul 29, 2020 · 3 comments
Open

Dynamic Update of tabs doesn't open a tab by default #337

DakkeOG opened this issue Jul 29, 2020 · 3 comments

Comments

@DakkeOG
Copy link

DakkeOG commented Jul 29, 2020

So I have a React Component with a tablist. If I make it Tab 1 and Tab 2 with Tabpanel 1 and 2 everything works fine.
However, if I have an array called 'Types' that gets filled in the componentDidMount(), it re-renders my Tabs, but in my browser, none of the tabs is opened. Meaning, I have to click one in order to open it. adding defaultIndex={0} didn't help.

This is what I render;

`

    <TabList>
      {types.map(type => <Tab><div className={styles.tab}>{type.value}</div></Tab>)}
    </TabList>

    {types.map(type =>
      <TabPanel>
        { <p>{type.value}</p> }
      </TabPanel>
    )}

  </Tabs>`
@polarmutex
Copy link

I solved this by switching the mode to controlled and controlling the state in your own react component (using selectedIndex)

@WisetrackPeru
Copy link

Please could you share how you solved it I have the same problem

@zacharytyhacz
Copy link

I have a similar issue with using map.

In my case, each <Tab> and corresponding <TabPanel> are wrapped with an Auth Guard component which hides/shows the children based on permissions.

Due to the Auth Guard component being async to decide if to show children, the Tabs get rendered at different times messing up the tab indexing.

I really wish the resetIdCounter() function was client side, that's all I would need.

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

4 participants