-
Notifications
You must be signed in to change notification settings - Fork 561
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] Wrong tab selected when tab array changes #828
Comments
Another observation: Even if you just simply add a new tab without even updating the selected tab index, the selected tab automatically shifts one to the left. |
And additional example of lazy loading tab. Started at |
Same issue here! The default "selected" styling is applied to the newly added tab (without it being selected) and the index within the context is invalid. |
Can confirm this issue, I also ran into it. A quick and hacky solution would be adding a key to the Forked and fixed the reproducible example: https://codesandbox.io/s/eager-nova-32edn?file=/src/App.tsx |
I'm experiencing the same issue! I'm pretty sure it used to work just fine in prior versions so it must have been introduced in one of the last releases. |
Any update? |
Using a key worked well for me! |
Thanks @jasikpark. using key worked for me too. I think this is a subtle bug that should be fixed. |
🐛 Bug report
Current Behavior
I'm working an application where we use @reach/tabs to manage our tabs. The list of tabs can change—both in length and in the ordering of tabs—when the user is using the app. We're using the tabs in a controlled way, i.e. we provide an
index
andonChange
to the Tabs component.I'm currently seeing three issues:
index
to the last index in the array, the second-to-last tab is selected. When I add more tabs, the selected tab doesn't change. It seems to be set to the last element of the original array, before any additions.If I inspect the components, it seems that the right Tab component is receiving the
isSelected = true
prop, but the CSS styles are incorrect. If I unmount the component and remount it, the correct tab is shown.Is this a bug or am I using the library incorrectly? Might this be caused by some sort of tab array caching and/or the caching of the CSS styles?
Expected behavior
I would expect the
index
number to select the right tab.Reproducible example
CodeSandbox example
Suggested solution(s)
N/A
Additional context
N/A
Your environment
The text was updated successfully, but these errors were encountered: