Skip to content

Navigation Block: Rotate submenu indicator icons on submenu expansion #70442

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

Merged

Conversation

shrivastavanolo
Copy link
Contributor

What?

Closes #35636
Follow up to #70307 #70334 #70427

Adds visual feedback to the Navigation block submenu toggle by rotating the nested submenu indicator icon when it is expanded and makes sure that the submenu label does not get inverted along with the icon.

Why?

Currently, opening a submenu does not change the downward arrow icon. Ideally, the icon should flip in the opposite direction to indicate the submenu is expanded.

How?

  • Rotates submenu icons using transform: rotate(180deg) when aria-expanded="true" is set on the toggle.
  • Uses rotate() to correctly support horizontally and vertically expanding nested submenus.
  • With "Open on click" option enabled: aria-expanded is on the button and the icon is it's next sibling while with "Open on click" disabled: aria-expanded is on the icon itself. This PR takes care of both structures while adding css rulesets.

Testing Instructions

  1. Open a post or page in the editor.
  2. Insert a Navigation block.
  3. Add a menu item with a submenu (child items).
  4. Add nested submenus under one of the child items.
  5. Click the parent item to expand the submenu.
  6. Observe the submenu arrow icon:
    • It should rotate away from the submenu when expanded.
    • It should return to point toward the submenu when collapsed.
  7. Enable "Open on click" on the Navigation block and repeat step 6.

Screenshots or screencast

Before

Screen.Recording.2025-06-16.at.5.07.22.PM.mov

After

Screen.Recording.2025-06-16.at.5.09.25.PM.mov

*note: The padding issue seen above in the nested submenu block item ("Open on click" enabled) is not caused by this PR. I'll create an issue for that shortly.

Copy link

github-actions bot commented Jun 16, 2025

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @ShreyaShrivastava@192.168.1.12.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: shreyashrivastava@192.168.1.12.

Co-authored-by: shrivastavanolo <shreya0shrivastava@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: hanneslsm <hanneslsm@git.wordpress.org>
Co-authored-by: karmatosed <karmatosed@git.wordpress.org>
Co-authored-by: jacobcassidy <jacobcassidy@git.wordpress.org>

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

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I believe there are two issues that need to be discussed and resolved here:

Arrows in nested menus

First, let's discuss and decide whether the arrows should be flipped in nested menus:

image

Personally, I prefer not to flip them here.

Change which elements are flipped

It should not be the button itself that is flipped, but the svg element inside it. Otherwise, the position of the flipped icon will be incorrect.

Flip button element (current PR state):

actual

Flip svg inside button (my suggestion):

expected

@t-hamano t-hamano requested a review from a team June 16, 2025 12:52
@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Navigation Affects the Navigation Block labels Jun 16, 2025
@hanneslsm
Copy link

hanneslsm commented Jun 16, 2025

Personally, I prefer not to flip them here.

I agree. It looks likes clicking on the link left to the menu would close the sub-menu, but that's not the case.
Also, at least in macOS this it's not a common pattern to flip the right facing arrows.

CleanShot 2025-06-16 at 15 43 55@2x

@shrivastavanolo
Copy link
Contributor Author

Changes made:

  1. Targeted svg directly instead of button.
  2. Arrows in nested menus aren't flipped.
Screen.Recording.2025-06-16.at.7.37.15.PM.mov

Note:
The following existing core media query:

@media (min-width: 782px) {
  .wp-block-navigation .has-child .wp-block-navigation__submenu-container .wp-block-navigation__submenu-icon svg {
    transform: rotate(-90deg);
  }
}

overrides the submenu icon svg on expansion, preventing nested submenu icons from rotating which is what was required here.

@shrivastavanolo shrivastavanolo requested a review from t-hamano June 16, 2025 15:06
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM! It appears to be working as expected in all scenarios.

Finally, I'd like to suggest some improvements to the code:

.wp-block-navigation-submenu__toggle {
	cursor: pointer;

	// Rotate submenu icon when open.
	&[aria-expanded="true"] {
		+ .wp-block-navigation__submenu-icon > svg,
		> svg {
			transform: rotate(180deg);
		}
	}
}
  • Use existing CSS selector
  • Make selectors simpler
  • I found the comments to be verbose, so shorten them

@t-hamano t-hamano merged commit 1d1a1ae into WordPress:trunk Jun 18, 2025
57 of 59 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.1 milestone Jun 18, 2025
@t-hamano
Copy link
Contributor

@shrivastavanolo Thank you for working on this PR!

*note: The padding issue seen above in the nested submenu block item ("Open on click" enabled) is not caused by this PR. I'll create an issue for that shortly.

Do you mind submitting a new issue regarding the above? I think that's clearly a bug that needs to be fixed.

chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…WordPress#70442)

* style: rotate submenu indicator icon on submenu expansion

* docs: add inline docs

* refactor: select svg instead of button

* refactor: use existing selectors

---------

Unlinked contributors: shreyashrivastava@192.168.1.12.

Co-authored-by: shrivastavanolo <shreya0shrivastava@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: hanneslsm <hanneslsm@git.wordpress.org>
Co-authored-by: karmatosed <karmatosed@git.wordpress.org>
Co-authored-by: jacobcassidy <jacobcassidy@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation Block: Flip submenu indicator arrow icon on click/hover
3 participants