-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Navigation: Show inserter when Navigation Submenu block is selected #71578
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
Navigation: Show inserter when Navigation Submenu block is selected #71578
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +17 B (0%) Total Size: 1.95 MB
ℹ️ View Unchanged
|
|
Tests are failing because there are two inserters visible (in the submenu dropdown and alongside the main nav itself). |
ce41e71 to
8539d4a
Compare
|
Flaky tests detected in b4e1cf1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18167944737
|
scruffian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few nits, but this looks good 🚢
| isImmediateParentOfSelectedBlock, | ||
| selectedBlockHasChildren, | ||
| isSelected, | ||
| hasSelectedDescendant, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to call this hasSelectedInnerBlock, so it matches the selector name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm...I'm thinking about the logic here. Does it actually make sense? I'm wondering if there are edge cases here in terms of what's selected at what level of depth 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this some more and I think hasSelectedDescendant is actually the better name here.
The variable name should describe what it represents rather than which function was used to get it.
hasSelectedDescendant tells you "this block has a selected descendant somewhere in its hierarchy". hasSelectedInnerBlock might be confusing because it could sound like "does this block have inner blocks?" rather than "does this block have a selected descendant?"
| } ) => { | ||
| await pageUtils.pressKeys( 'ArrowDown' ); | ||
| await navigation.useBlockInserter(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this deliberate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy/paste cos I put the "fix" in the wrong place initially.
Previously, the Navigation block's inserter would only show when: - The Navigation block itself was selected, OR - A direct child of the Navigation block was selected This change adds support for showing the inserter when any descendant block is selected, including Navigation Submenu blocks. This allows users to add new navigation items at the top level even when working with submenus. Changes: - Added hasSelectedDescendant selector to check for any selected descendant - Updated renderAppender logic to include hasSelectedDescendant condition - Maintains all existing behavior while adding new functionality Fixes the issue where the Navigation block inserter was not visible when a Navigation Submenu block was selected.
c371489 to
b4e1cf1
Compare
What
Fixes the issue where the Navigation block's inserter was not visible when a Navigation Submenu block was selected.
Why
Previously, the Navigation block's inserter would only show when:
This meant that when working with Navigation Submenu blocks (which are descendants, not direct children), users couldn't access the Navigation block's inserter to add new top-level navigation items.
How
hasSelectedDescendantselector to check for any selected descendant block at any nesting levelrenderAppenderlogic to includehasSelectedDescendantconditionTesting
Screenshots
[Screenshots to be added]
Breaking Changes
None - this is a pure enhancement that adds functionality without changing existing behavior.