From 8763709ab2542e304a7ffd898657b6fa721e263f Mon Sep 17 00:00:00 2001 From: Mayank-Tripathi32 Date: Wed, 25 Dec 2024 18:50:11 +0530 Subject: [PATCH] feat: fix drop zone issue in sub menu components --- .../components/use-block-drop-zone/index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/index.js b/packages/block-editor/src/components/use-block-drop-zone/index.js index 529eb199fb76a..a5351ce40baf6 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/index.js @@ -257,17 +257,24 @@ export function isDropTargetValid( // Work out if dragged blocks have an allowed parent and if so // check target block matches the allowed parent. - const draggedBlockTypes = draggedBlockNames.map( ( name ) => - getBlockType( name ) - ); + const draggedBlockTypes = draggedBlockNames.map( ( name ) => { + const blockType = getBlockType( name ); + return { + name, + parent: blockType.parent || [], + }; + } ); const targetMatchesDraggedBlockParents = draggedBlockTypes.every( ( block ) => { + const [ firstParent ] = draggedBlockTypes[ 0 ]?.parent || []; const [ allowedParentName ] = block?.parent || []; - if ( ! allowedParentName ) { + if ( ! firstParent && ! allowedParentName ) { return true; } - - return allowedParentName === targetBlockName; + return ( + firstParent === allowedParentName || + allowedParentName === targetBlockName + ); } );