-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Respect selectedIndex
for controlled <Tab/>
components
#3037
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
RobinMalfait
force-pushed
the
fix/issue-2989
branch
from
March 15, 2024 11:03
b738784
to
98f0d9e
Compare
thecrypticace
approved these changes
Mar 15, 2024
RobinMalfait
added a commit
that referenced
this pull request
Apr 15, 2024
* ensure controlled `<Tab>` components respect the `selectedIndex` * update changelog * use older syntax in tests * run prettier to fix lint step
This was referenced May 18, 2024
This was referenced May 21, 2024
This was referenced May 26, 2024
This was referenced May 28, 2024
This was referenced May 31, 2024
This was referenced Jun 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where the
selectedIndex
doesn't always match the visibly selected tab, when using a controlled<Tab />
component.The
<Tab />
component can be used in 2 ways:selectedIndex
is managed internally by the component itself.selectedIndex
is managed by the parent component (or in other words, you).When the
<Tab />
component is uncontrolled, and thus the state is managed internally, then we try to make sure that we maintain the active tab. For example, if you have the following tabs:Right now
Tab bar
is the active one, if you now add or remove a tab beforeTab bar
then we still wantTab bar
to be the active one.When
Tab foo
is deleted:When
Tab qux
is added:This behaviour makes sense, because otherwise you are constantly changing the active tab, which is typically not what you want.
The problem is that we also did this when the component was controlled, but then the
selectedIndex
value is not in sync with what's actually visible. This means that the behaviour looks like this:When
Tab foo
is deleted:When
Tab qux
is added:Instead, we will now always use the
selectedIndex
value to determine the active tab, and not try to maintain the active tab when the component is controlled.When
Tab foo
is deleted:When
Tab qux
is added:Since it is a controlled component, it is up to you to keep the
selectedIndex
in sync with what you want if you add or remove tabs.Fixes: #2989