Skip to content

Commit

Permalink
List View: Expand state if a block is dragged to within a collapsed b…
Browse files Browse the repository at this point in the history
…lock in the editor canvas
  • Loading branch information
andrewserong committed Nov 24, 2023
1 parent 55d0c84 commit cecdde0
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,15 +36,20 @@ 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( {
type: 'expand',
clientIds: selectedBlockParentClientIds,
} );
}
}, [ firstSelectedBlockClientId ] );
}, [
firstSelectedBlockClientId,
selectedBlockParentClientIds,
selectedTreeId,
setExpandedState,
] );

return {
setSelectedTreeId,
Expand Down

0 comments on commit cecdde0

Please sign in to comment.