Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 8 additions & 57 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

/**
Expand Down Expand Up @@ -289,7 +284,6 @@ export default function NavigationLinkEdit( {
url,
opensInNewTab,
};
const { showSubmenuIcon } = context;
const { saveEntityRecord } = useDispatch( coreStore );
const {
replaceBlock,
Expand All @@ -306,9 +300,7 @@ export default function NavigationLinkEdit( {
isAtMaxNesting,
isTopLevelLink,
isParentOfSelectedBlock,
isImmediateParentOfSelectedBlock,
hasDescendants,
selectedBlockHasDescendants,
userCanCreatePages,
userCanCreatePosts,
} = useSelect(
Expand Down Expand Up @@ -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();
}
}, [] );

/**
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -727,13 +684,7 @@ export default function NavigationLinkEdit( {
/>
</Popover>
) }
{ hasDescendants && showSubmenuIcon && (
<span className="wp-block-navigation-link__submenu-icon wp-block-navigation__submenu-icon">
<ItemSubmenuIcon />
</span>
) }
</a>
<div { ...innerBlocksProps } />
</div>
</Fragment>
);
Expand Down