Skip to content

Commit

Permalink
Block Hooks: Take controlled blocks into account for toggle state (#5…
Browse files Browse the repository at this point in the history
…9367)

This is necessary to the correctly set the toggle state for hooked blocks inserted as first child or last child of the Navigation block.

Unlinked contributors: pkuliga.

Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: tjcafferkey <tomjcafferkey@git.wordpress.org>
Co-authored-by: michalczaplinski <czapla@git.wordpress.org>
  • Loading branch information
4 people authored and getdave committed Feb 27, 2024
1 parent a446441 commit a3ab0c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/block-editor/src/hooks/block-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ function BlockHooksControlPure( { name, clientId } ) {

const { blockIndex, rootClientId, innerBlocksLength } = useSelect(
( select ) => {
const { getBlock, getBlockIndex, getBlockRootClientId } =
const { getBlocks, getBlockIndex, getBlockRootClientId } =
select( blockEditorStore );

return {
blockIndex: getBlockIndex( clientId ),
innerBlocksLength: getBlock( clientId )?.innerBlocks?.length,
innerBlocksLength: getBlocks( clientId )?.length,
rootClientId: getBlockRootClientId( clientId ),
};
},
Expand All @@ -49,7 +49,7 @@ function BlockHooksControlPure( { name, clientId } ) {

const hookedBlockClientIds = useSelect(
( select ) => {
const { getBlock, getGlobalBlockCount } =
const { getBlocks, getGlobalBlockCount } =
select( blockEditorStore );

const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(
Expand All @@ -69,15 +69,15 @@ function BlockHooksControlPure( { name, clientId } ) {
// Any of the current block's siblings (with the right block type) qualifies
// as a hooked block (inserted `before` or `after` the current one), as the block
// might've been automatically inserted and then moved around a bit by the user.
candidates = getBlock( rootClientId )?.innerBlocks;
candidates = getBlocks( rootClientId );
break;

case 'first_child':
case 'last_child':
// Any of the current block's child blocks (with the right block type) qualifies
// as a hooked first or last child block, as the block might've been automatically
// inserted and then moved around a bit by the user.
candidates = getBlock( clientId ).innerBlocks;
candidates = getBlocks( clientId );
break;
}

Expand Down

0 comments on commit a3ab0c7

Please sign in to comment.