diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js
index d022817295a512..07e9881c4d1cb7 100644
--- a/packages/block-library/src/navigation-link/edit.js
+++ b/packages/block-library/src/navigation-link/edit.js
@@ -21,8 +21,6 @@ import { displayShortcut, isKeyboardEvent, ENTER } from '@wordpress/keycodes';
import { __, sprintf } from '@wordpress/i18n';
import {
BlockControls,
- InnerBlocks,
- __experimentalUseInnerBlocksProps as useInnerBlocksProps,
InspectorControls,
RichText,
__experimentalLinkControl as LinkControl,
@@ -45,11 +43,8 @@ import { store as coreStore } from '@wordpress/core-data';
/**
* Internal dependencies
*/
-import { ItemSubmenuIcon } from './icons';
import { name } from './block.json';
-const ALLOWED_BLOCKS = [ 'core/navigation-link' ];
-
const MAX_NESTING = 5;
/**
@@ -289,7 +284,6 @@ export default function NavigationLinkEdit( {
url,
opensInNewTab,
};
- const { showSubmenuIcon } = context;
const { saveEntityRecord } = useDispatch( coreStore );
const {
replaceBlock,
@@ -306,9 +300,7 @@ export default function NavigationLinkEdit( {
isAtMaxNesting,
isTopLevelLink,
isParentOfSelectedBlock,
- isImmediateParentOfSelectedBlock,
hasDescendants,
- selectedBlockHasDescendants,
userCanCreatePages,
userCanCreatePosts,
} = useSelect(
@@ -384,14 +376,18 @@ export default function NavigationLinkEdit( {
replaceBlock( clientId, newSubmenu );
}
- // Show the LinkControl on mount if the URL is empty
- // ( When adding a new menu item)
- // This can't be done in the useState call because it conflicts
- // with the autofocus behavior of the BlockListBlock component.
useEffect( () => {
+ // Show the LinkControl on mount if the URL is empty
+ // ( When adding a new menu item)
+ // This can't be done in the useState call because it conflicts
+ // with the autofocus behavior of the BlockListBlock component.
if ( ! url ) {
setIsLinkOpen( true );
}
+ // If block has inner blocks, transform to Submenu.
+ if ( hasDescendants ) {
+ transformToSubmenu();
+ }
}, [] );
/**
@@ -519,45 +515,6 @@ export default function NavigationLinkEdit( {
blockProps.onClick = () => setIsLinkOpen( true );
}
- // Always use overlay colors for submenus
- const innerBlocksColors = getColors( context, true );
- const innerBlocksProps = useInnerBlocksProps(
- {
- className: classnames(
- 'wp-block-navigation-link__container',
- 'wp-block-navigation__submenu-container',
- {
- 'is-parent-of-selected-block': isParentOfSelectedBlock,
- 'has-text-color': !! (
- innerBlocksColors.textColor ||
- innerBlocksColors.customTextColor
- ),
- [ `has-${ innerBlocksColors.textColor }-color` ]: !! innerBlocksColors.textColor,
- 'has-background': !! (
- innerBlocksColors.backgroundColor ||
- innerBlocksColors.customBackgroundColor
- ),
- [ `has-${ innerBlocksColors.backgroundColor }-background-color` ]: !! innerBlocksColors.backgroundColor,
- }
- ),
- style: {
- color: innerBlocksColors.customTextColor,
- backgroundColor: innerBlocksColors.customBackgroundColor,
- },
- },
- {
- allowedBlocks: ALLOWED_BLOCKS,
- renderAppender:
- ( isSelected && hasDescendants ) ||
- ( isImmediateParentOfSelectedBlock &&
- ! selectedBlockHasDescendants ) ||
- // Show the appender while dragging to allow inserting element between item and the appender.
- hasDescendants
- ? InnerBlocks.DefaultAppender
- : false,
- }
- );
-
const classes = classnames(
'wp-block-navigation-link__content',
'wp-block-navigation-item__content',
@@ -727,13 +684,7 @@ export default function NavigationLinkEdit( {
/>
) }
- { hasDescendants && showSubmenuIcon && (
-
-