Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Hooks: Take controlled blocks into account for toggle state #59367

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading