From 4155c0071adaa1796b5cf47ac187486913bb9cef Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:22:25 +1100 Subject: [PATCH] List View: Expand state if a block is dragged to within a collapsed block in the editor canvas (#56493) --- .../use-list-view-expand-selected-item.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/list-view/use-list-view-expand-selected-item.js b/packages/block-editor/src/components/list-view/use-list-view-expand-selected-item.js index 09b5e09e4713a3..f84419dc1db933 100644 --- a/packages/block-editor/src/components/list-view/use-list-view-expand-selected-item.js +++ b/packages/block-editor/src/components/list-view/use-list-view-expand-selected-item.js @@ -27,12 +27,6 @@ export default function useListViewExpandSelectedItem( { [ firstSelectedBlockClientId ] ); - const parentClientIds = - Array.isArray( selectedBlockParentClientIds ) && - selectedBlockParentClientIds.length - ? selectedBlockParentClientIds - : null; - // Expand tree when a block is selected. useEffect( () => { // If the selectedTreeId is the same as the selected block, @@ -42,7 +36,7 @@ export default function useListViewExpandSelectedItem( { } // If the selected block has parents, get the top-level parent. - if ( parentClientIds ) { + if ( selectedBlockParentClientIds?.length ) { // If the selected block has parents, // expand the tree branch. setExpandedState( { @@ -50,7 +44,12 @@ export default function useListViewExpandSelectedItem( { clientIds: selectedBlockParentClientIds, } ); } - }, [ firstSelectedBlockClientId ] ); + }, [ + firstSelectedBlockClientId, + selectedBlockParentClientIds, + selectedTreeId, + setExpandedState, + ] ); return { setSelectedTreeId,