Skip to content

Commit

Permalink
Block Hooks: Take controlled blocks into account for toggle state
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Feb 26, 2024
1 parent a5721d9 commit e1aee89
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 e1aee89

Please sign in to comment.