Changing order of tabs causes selected tab to not match the rendered TabPanel
See original GitHub issueThank you for a wonderful library!
🐛 Bug report
I am using a controlled Tabs component where I loop over an array to render the individual Tab
components. The tabs array is ordered based on some property of the array items and the order may change. When the array changes due to a reordering the selected Tab
is no longer in sync with the selected TabPanel
.
💥 Steps to reproduce
- Create a controlled Tabs component
- Model tabs as an array and render in a loop
- Change order of the items in the array
- See selected
Tab
andTabPanel
out of sync.
💻 Link to reproduction
https://codesandbox.io/s/controlled-tabs--ordered-tabs-ompqp?file=/src/App.tsx
🧐 Expected behavior
Selected Tab
and TabPanel
are in sync.
🌍 System information
Software | Version(s) |
---|---|
Chakra UI | 1.3.2 |
Browser | 88 |
Operating System | macOS 11.2 |
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Reactjs material ui prevent re-render tabs on enter
I have built a material-ui based UI containing tabs in reactJS. Anytime a tab is selected, the content ...
Read more >Tabs - Chakra UI
Tabs expects TabList and TabPanels as children. The order doesn't matter, you can have TabList at the top, at the bottom, or both....
Read more >apex:tabPanel issue with setting the correct tab after validation ...
This doesn't work and everytime I land on the first tab. To fix this I am setting the rootController's selectedTab variable from the...
Read more >Tabs - Chakra UI
A React component that helps you build accessible tabs, by providing keyboard interactions and ARIA attributes described in the WAI-ARIA Tab Panel Design ......
Read more >Set the tab order for controls - Microsoft Support
In Access desktop databases you can change the tab order of controls on forms and reports, remove a control from the tab order,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh boy. I likely just built something at work that suffers from this same issue 😬
Appears to be caused by a disconnect between
index
coming fromuseDescendant
and theindex
coming fromvalidChildren.map
insideuseTabPanels
. https://github.com/chakra-ui/chakra-ui/blob/500b1eea0876909b670c103ffa354b2b77ff024f/packages/tabs/src/use-tabs.ts#L361-L363index
andselectedIndex
no longer correspond once the order of items changes.neither is mine 😦