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: Fixed styling tab not opening on themes without style variations on mobile & desktop #67537

Conversation

Mayank-Tripathi32
Copy link
Contributor

resolves #67532

What?

This PR adds to="/styles" and aria-current={ name === 'styles' } to SidebarNavigationItem to ensure the Styles tab works correctly on mobile devices.

Why?

When a block theme lacks global style variations, the top-level Styles panel in the Site Editor does not open on mobile when using Gutenberg 19.7 or the nightly build. This PR resolves the issue to ensure consistent behavior across all themes.

How?

The conditional rendering for SidebarNavigationItem was updated. The onClick logic was removed with the introduction of the Styles panel in 2a18aae3768da80f94e437c16e8d56e5a9a45e03 , but it made it work only for themes with global variations. This patch ensures the SidebarNavigationItem opens the Styles panel for all themes, regardless of variations.

if ( hasGlobalStyleVariations ) {
   	return (
   		<SidebarNavigationItem
   			{ ...props }
   			to="/styles"
   			uid="global-styles-navigation-item"
   			aria-current={ name === 'styles' }
   		/>
   	);
   }
   return <SidebarNavigationItem { ...props } to="/styles" aria-current={ name === 'styles' } />;

Testing Instructions

  1. Use a block theme without style variations, like https://wordpress.org/themes/onyxpulse/
  2. Ensure you're using at least GB 19.7.
  3. Open this on your phone or use browser tools to pull up on mobile.
  4. Open Appearance > Editor
  5. Try to select Styles and notice it properly opens up the Styles panel.
  6. Switch to a theme with style variations, like https://wordpress.org/themes/twentytwentyfive/
  7. Open Appearance > Editor
  8. Try to select Styles and notice it properly opens up the Styles panel.

Screenshots or screencast

Screen.Recording.2024-12-03.at.11.54.32.PM.mov

Copy link

github-actions bot commented Dec 3, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: annezazu <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mayank-Tripathi32
Copy link
Contributor Author

@annezazu @supernovia Please have a look at PR. Thank you

@annezazu
Copy link
Contributor

annezazu commented Dec 3, 2024

Thanks so much for working on this! It works great for me in my testing. I can't speak to the code though.

@annezazu
Copy link
Contributor

annezazu commented Dec 3, 2024

Video for good measure:

works.mov

@@ -41,7 +41,13 @@ export function SidebarNavigationItemGlobalStyles( props ) {
/>
);
}
return <SidebarNavigationItem { ...props } />;
return (
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for getting this PR up! I'll test further later today.

I'm wondering if we need the hasGlobalStyleVariations condition at all. 🤔

E.g.,

export function SidebarNavigationItemGlobalStyles( props ) {
	const { name } = useLocation();
	return (
		<SidebarNavigationItem
			{ ...props }
			to="/styles"
			uid="global-styles-navigation-item"
			aria-current={ name === 'styles' }
		/>
	);
}

I'll investigate later.

Also, not related to this PR, but there's a persistent JS error for sidebar items on mobile: #67467 (comment)

Just mentioning in case you see it and are wondering 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about removing the condition too. But after looking at the original code, I saw that the condition was there and the uid was missing in the default return. To keep the code consistent and working as expected, I decided to leave it as is.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, thanks for the context. That's a good point. Anyway, I'll test as soon as I can today and we'll aim to get the fix in ASAP.

Copy link
Member

Choose a reason for hiding this comment

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

I still think a lot of this code is superfluous and doubles up on things.

For example, most of the props could be passed to SidebarNavigationItemGlobalStyles in MainSidebarNavigationContent.

			<SidebarNavigationItemGlobalStyles
				to="/styles"
				uid="global-styles-navigation-item"
				icon={ styles }
			>
				{ __( 'Styles' ) }
			</SidebarNavigationItemGlobalStyles>

With the same effect.

Removing the condition doesn't have any side effects as far as I can see, but I agree that we can take the cautious route to fix the bug.

I can get a follow up to clean up the code and we can get folks who have commented on recent changes to routing here to chime in.

cc @youknowriad and @t-hamano for visibility

@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended [Package] Edit Site /packages/edit-site Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) labels Dec 3, 2024
Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

Fixes the issue for me, thanks a lot @Mayank-Tripathi32

I'll add a clean up PR as a follow up as I suspect that the props can be tidied up and we don't need the hasGlobalStyleVariations condition.

@@ -41,7 +41,13 @@ export function SidebarNavigationItemGlobalStyles( props ) {
/>
);
}
return <SidebarNavigationItem { ...props } />;
return (
Copy link
Member

Choose a reason for hiding this comment

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

I still think a lot of this code is superfluous and doubles up on things.

For example, most of the props could be passed to SidebarNavigationItemGlobalStyles in MainSidebarNavigationContent.

			<SidebarNavigationItemGlobalStyles
				to="/styles"
				uid="global-styles-navigation-item"
				icon={ styles }
			>
				{ __( 'Styles' ) }
			</SidebarNavigationItemGlobalStyles>

With the same effect.

Removing the condition doesn't have any side effects as far as I can see, but I agree that we can take the cautious route to fix the bug.

I can get a follow up to clean up the code and we can get folks who have commented on recent changes to routing here to chime in.

cc @youknowriad and @t-hamano for visibility

@ramonjd ramonjd merged commit f32a49e into WordPress:trunk Dec 3, 2024
73 of 76 checks passed
@github-actions github-actions bot added this to the Gutenberg 19.9 milestone Dec 3, 2024
@ramonjd
Copy link
Member

ramonjd commented Dec 3, 2024

Now I remember 😄 The style panel used to only contain variations.

See: #50573

Since #65619 it's no longer the case.

I'll throw up a clean up PR

@ramonjd
Copy link
Member

ramonjd commented Dec 3, 2024

I'll throw up a clean up PR

#67545

@ramonjd ramonjd removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Dec 4, 2024
im3dabasia pushed a commit to im3dabasia/gutenberg that referenced this pull request Dec 4, 2024
… on mobile & desktop (WordPress#67537)

Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: annezazu <[email protected]>
michalczaplinski pushed a commit that referenced this pull request Dec 5, 2024
… on mobile & desktop (#67537)

Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: annezazu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Edit Site /packages/edit-site [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Styles: top level styles does not open on mobile for sites using themes without style variations
3 participants