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 (#56493)
  • Loading branch information
andrewserong authored Nov 27, 2023
1 parent 26d96b6 commit 4155c00
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

1 comment on commit 4155c00

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4155c00.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7000212811
📝 Reported issues:

Please sign in to comment.