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

Fix tab panel initial tab selection #47100

Merged
merged 3 commits into from
Jan 12, 2023

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Jan 12, 2023

What?

Fixes #47079

Why?

From what I can tell there are two causes of the bug:

  1. The Navigation block's List View tab isn't declared on first render, it only becomes present in the tabs array on later renders.
  2. The TabPanel no longer supports lazily adding initial tabs after TabPanel: Add prop to allow disabling of a tab button #46471, it now always falls back to the first enabled tab in the tabs array.

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 initalTabName is declared, but there's no matching tab in the tabs array, the effect no longer makes a selection until it is in the tabs array.

This does leave a situation where initalTabName could 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

  1. Add a navigation block to a post and add some inner blocks to it
  2. In the nav block's block inspector List View interface, select the 'Edit block' button of one of the inner blocks
  3. Press the 'Go to parent' button at the top of the inspector panel when that inner block is selected.

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

@talldan talldan added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Jan 12, 2023
@talldan talldan requested a review from ajitbohra as a code owner January 12, 2023 06:20
@talldan talldan self-assigned this Jan 12, 2023

// If the currently selected tab becomes disabled, select the first enabled tab.
// (if there is one).
if ( firstEnabledTab ) {
Copy link
Contributor Author

@talldan talldan Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@talldan talldan force-pushed the fix/tab-panel-lazily-added-initial-tabs branch from 30ad7a3 to 9103fe2 Compare January 12, 2023 07:02
@github-actions
Copy link

github-actions bot commented Jan 12, 2023

Flaky tests detected in 9103fe2.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3899933660
📝 Reported issues:

@talldan talldan added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jan 12, 2023
Copy link
Contributor

@scruffian scruffian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@scruffian scruffian merged commit 4f0e10a into trunk Jan 12, 2023
@scruffian scruffian deleted the fix/tab-panel-lazily-added-initial-tabs branch January 12, 2023 11:04
@github-actions github-actions bot added this to the Gutenberg 15.1 milestone Jan 12, 2023
@ciampo
Copy link
Contributor

ciampo commented Jan 12, 2023

Thank you both for flagging the issue and working on a fix so quickly 🙏

@priethor priethor removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation Block List View: Open the inspector on the correct tab after editing an item
4 participants