-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Normalize the Navigation block appender behavior between canvas and list view contexts #71163
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
Conversation
|
Size Change: +86 B (0%) Total Size: 1.92 MB
ℹ️ View Unchanged
|
| onSelectOrClose( { | ||
| clientId: blockToInsert?.clientId, | ||
| } ); | ||
| onSelectOrClose( blockToInsert ); |
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.
This will be backwards compat as the new object will still contain clientId.
| @@ -1,5 +1,6 @@ | |||
| export const DEFAULT_BLOCK = { | |||
| name: 'core/navigation-link', | |||
| attributes: { type: 'page', kind: 'post-type' }, | |||
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.
This is needed to ensure the directly inserted block is the correct variation (i.e. Page) for Nav blocks.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
| const directInsert = useSelect( | ||
| ( select ) => { | ||
| const { getBlockListSettings } = select( blockEditorStore ); | ||
| const settings = getBlockListSettings( clientId ); | ||
| return settings?.directInsert || false; | ||
| }, | ||
| [ clientId ] | ||
| ); |
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.
This will cause ALL list views that have an inserter to mirror the behaviour set in the block list settings. This makes sense to me and I believe is limited to the Nav block as it's the only one able to consume the PrivateListView.
Confidence check appreciated.
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.
Aligning how it works makes sense to me. Not sure if we could move towards them using the same component/hook or if they're too fundamentally different.
Only code quality / performance feedback is that this useSelect could be merged with the one a few lines below to reduce the number of store subscriptions.
|
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. |
This works when I click in the sidebar to cancel link creation, but not when I click in the canvas: Screen.Recording.2025-08-14.at.13.42.33.mov |
|
This appears to be an issue relating to the canvas iframe. The Link UI is outside the iframe and thus the focusoutside logic doesn't seem to detect clicks within the editor canvas. If you click anywhere else in the editor UI other than the editor canvas the cleanup works fine. It's just selecting stuff inside the canvas. At this point I don't have a solution but essentially the |
92e661d to
b4c4291
Compare
packages/block-library/src/navigation/edit/menu-inspector-controls.js
Outdated
Show resolved
Hide resolved
b4c4291 to
2c8a604
Compare
| isAppender | ||
| selectBlockOnInsert={ false } | ||
| shouldDirectInsert={ false } | ||
| shouldDirectInsert={ directInsert } |
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 guess we don't have any instances where this is false anymore.
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.
It should mirror the block list settings.
…in list view When using the 'Add block' feature in the Navigation block's list view context, the original auto-inserted navigation link block was not being cleaned up when a different block was selected via the QuickInserter. This caused duplicate blocks to remain in the list view. The fix adds a wrapper function handleSetInsertedBlock that removes the original inserted block before setting the new selected block, ensuring only the newly selected block remains in the list view. This aligns the list view behavior with the canvas context behavior.
…view When selecting a different block from the QuickInserter in the Navigation block's list view context, the original auto-inserted block was being removed with automatic block selection enabled. This caused focus stealing that closed the list view and switched to the canvas. The fix adds preventBlockSelection = false to removeBlock() calls to prevent automatic block selection, keeping the list view open and maintaining proper focus behavior.
…arity Rename the setInsertedBlock prop to onBlockInsert across the Navigation block components to make the prop name more generic and descriptive of its purpose as a callback function that's called when a block is inserted. This improves code readability and makes the prop name more reusable across different contexts while maintaining all existing functionality.
- Add useEditorCanvasCleanup hook to handle iframe interaction cleanup - Fixes issue where auto-inserted Navigation Link blocks weren't cleaned up when clicking on canvas blocks in List View context - Uses standardized iframe selector approach consistent with rest of codebase - Hook automatically manages event listener lifecycle based on LinkUI visibility
- Add useEditorCanvasCleanup hook to handle iframe interaction cleanup - Fixes issue where auto-inserted Navigation Link blocks weren't cleaned up when clicking on canvas blocks in List View context - Uses standardized iframe selector approach consistent with rest of codebase - Hook automatically manages event listener lifecycle based on LinkUI visibility
718929b to
b9cb6eb
Compare
|
I've tested this and it's looking pretty solid to me. Just waiting on a review. Update: turns out I forgot to push my changes 🤦 Should be working now @scruffian |
|
Thinking about follow ups here:
|
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.
This is working well now. A much better UX too, let's bring it in...
- Create shared BackButton component to eliminate duplication - Replace duplicated back button implementations in LinkUIBlockInserter and LinkUIPageCreator - Standardize back button behavior and styling across components - Remove unused chevron icon imports from page-creator.js - Add proper JSDoc documentation for BackButton component This is the first phase of LinkUI duplication cleanup as discussed in PR #71163 follow-ups.
- Create useDialogIds hook to eliminate duplicated useInstanceId calls - Replace duplicated accessibility ID generation in LinkUIBlockInserter and UnforwardedLinkUI - Maintain correct component parameters (LinkControl vs LinkUI) for proper ID generation - Standardize dialog accessibility ID pattern across components - Export hook for potential reuse in other components This is the second phase of LinkUI duplication cleanup as discussed in PR #71163 follow-ups.
- Create shared DialogWrapper component that handles all dialog concerns internally - Eliminate useDialogIds hook by inlining useInstanceId calls directly in DialogWrapper - Derive component, componentName, and backButtonClassName from className prop - Move useFocusOnMount logic inside DialogWrapper for complete encapsulation - Replace duplicated dialog structures in LinkUIBlockInserter and LinkUIPageCreator - Fix useDialogIds reference error in main LinkUI component - Maintain all existing CSS styling and accessibility features - Fix nested ternary linting error with if/else statements This completes the major refactoring of LinkUI duplication cleanup as discussed in PR #71163 follow-ups.
* refactor: extract shared BackButton component from LinkUI - Create shared BackButton component to eliminate duplication - Replace duplicated back button implementations in LinkUIBlockInserter and LinkUIPageCreator - Standardize back button behavior and styling across components - Remove unused chevron icon imports from page-creator.js - Add proper JSDoc documentation for BackButton component Co-authored-by: getdave <[email protected]> Co-authored-by: scruffian <[email protected]> This is the first phase of LinkUI duplication cleanup as discussed in PR #71163 follow-ups. * refactor: extract useDialogIds hook for dialog accessibility IDs - Create useDialogIds hook to eliminate duplicated useInstanceId calls - Replace duplicated accessibility ID generation in LinkUIBlockInserter and UnforwardedLinkUI - Maintain correct component parameters (LinkControl vs LinkUI) for proper ID generation - Standardize dialog accessibility ID pattern across components - Export hook for potential reuse in other components This is the second phase of LinkUI duplication cleanup as discussed in PR #71163 follow-ups. * refactor: create DialogWrapper component with minimal API - Create shared DialogWrapper component that handles all dialog concerns internally - Eliminate useDialogIds hook by inlining useInstanceId calls directly in DialogWrapper - Derive component, componentName, and backButtonClassName from className prop - Move useFocusOnMount logic inside DialogWrapper for complete encapsulation - Replace duplicated dialog structures in LinkUIBlockInserter and LinkUIPageCreator - Fix useDialogIds reference error in main LinkUI component - Maintain all existing CSS styling and accessibility features - Fix nested ternary linting error with if/else statements This completes the major refactoring of LinkUI duplication cleanup as discussed in PR #71163 follow-ups. * refactor: extract LinkUIBlockInserter to separate file and consolidate BackButton - Extract LinkUIBlockInserter component to block-inserter.js for consistency with page-creator.js - Consolidate BackButton component into dialog-wrapper.js since it's only used there - Fix import issues with privateApis in block-inserter.js - Remove separate back-button.js file to reduce file count - Clean up unused imports in link-ui.js after component extraction - Fix JSDoc alignment in block-inserter.js - Maintain all existing functionality while improving file organization This completes the component extraction phase of the LinkUI duplication cleanup. * refactor: simplify DialogWrapper instance ID generation Use DialogWrapper as the component for useInstanceId instead of deriving it from className. This removes unnecessary complexity and unused imports. * Standardise ID generation in Dialog
What
This PR aligns the behavior of Navigation block appenders between canvas and list view contexts. Currently, the list view appender uses a different insertion flow than the canvas appender, leading to inconsistent user experience.
Why
The Navigation block's list view and canvas contexts should provide consistent appender behavior. Users expect the same insertion experience regardless of whether they're editing in the canvas or using the list view sidebar. This alignment improves the overall user experience and reduces confusion.
This should open the door for improved UX in #71192.
How
directInsertanddefaultBlocksettings configured in the Navigation blockKnown follow ups
+inserter tooltip to beAdd pagein both List View and canvas.Testing
Screenshots
Screen.Capture.on.2025-08-14.at.11-46-06.mp4
Key Changes from Trunk
directInsertanddefaultBlocksettings