Fix tab panel initial tab selection#47100
Merged
Conversation
talldan
commented
Jan 12, 2023
|
|
||
| // If the currently selected tab becomes disabled, select the first enabled tab. | ||
| // (if there is one). | ||
| if ( firstEnabledTab ) { |
Contributor
Author
There was a problem hiding this comment.
The previous code didn't do so, but the component should probably consider a case where all tabs are disabled.
It might be handled elsewhere in the component though, I haven't really checked.
30ad7a3 to
9103fe2
Compare
|
Flaky tests detected in 9103fe2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3899933660
|
Contributor
|
Thank you both for flagging the issue and working on a fix so quickly 🙏 |
This file contains hidden or 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
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.
What?
Fixes #47079
Why?
From what I can tell there are two causes of the bug:
tabsarray on later renders.tabsarray.I did try looking to see if this could be fixed by always rendering the tab navigation block, but it's less than straightforward. The tab is added somewhat dynamically when there are fills in a slot. I struggled to see where the issue was coming from.
How?
This fixes the issue. If
initalTabNameis declared, but there's no matching tab in thetabsarray, the effect no longer makes a selection until it is in the tabs array.This does leave a situation where
initalTabNamecould be declared and the matching tab is never present, but I'd consider this implementor error (and the same issue could happen before #46471).I have refactored the code a bit here too. I personally found the code a little hard to understand with the added logic, so it's now a little more verbose, but hopefully easier to follow.
Testing Instructions
Expected - the List View tab should be selected again on the navigation block.
In trunk - the Appearance tab is selected.
Screenshots or screencast
Before
Kapture.2023-01-12.at.14.18.34.mp4
After
Kapture.2023-01-12.at.14.16.22.mp4