From b43e869bf8a6adcc8181f0c3bf5f217ce75de9b6 Mon Sep 17 00:00:00 2001 From: adithya-naik Date: Thu, 30 Apr 2026 23:28:50 +0530 Subject: [PATCH 1/2] Fix: Buttons block shows inserter picker when multiple allowed blocks are registered --- packages/block-library/src/buttons/edit.js | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/buttons/edit.js b/packages/block-library/src/buttons/edit.js index 6fb718475c2cac..02ae7988b2ad17 100644 --- a/packages/block-library/src/buttons/edit.js +++ b/packages/block-library/src/buttons/edit.js @@ -6,7 +6,11 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; +import { + useBlockProps, + useInnerBlocksProps, + store as blockEditorStore, +} from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { store as blocksStore } from '@wordpress/blocks'; @@ -25,27 +29,34 @@ const DEFAULT_BLOCK = { ], }; -function ButtonsEdit( { attributes, className } ) { +function ButtonsEdit( { attributes, className, clientId } ) { const { fontSize, layout, style } = attributes; const blockProps = useBlockProps( { className: clsx( className, { 'has-custom-font-size': fontSize || style?.typography?.fontSize, } ), } ); - const { hasButtonVariations } = useSelect( ( select ) => { - const buttonVariations = select( blocksStore ).getBlockVariations( - 'core/button', - 'inserter' - ); - return { - hasButtonVariations: buttonVariations.length > 0, - }; - }, [] ); + + const { hasButtonVariations, hasMultipleAllowedBlocks } = useSelect( + ( select ) => { + const buttonVariations = select( blocksStore ).getBlockVariations( + 'core/button', + 'inserter' + ); + const allowedBlocks = + select( blockEditorStore ).getAllowedBlocks( clientId ); + return { + hasButtonVariations: buttonVariations.length > 0, + hasMultipleAllowedBlocks: + allowedBlocks && allowedBlocks.length > 1, + }; + }, + [ clientId ] + ); const innerBlocksProps = useInnerBlocksProps( blockProps, { defaultBlock: DEFAULT_BLOCK, - // This check should be handled by the `Inserter` internally to be consistent across all blocks that use it. - directInsert: ! hasButtonVariations, + directInsert: ! hasButtonVariations && ! hasMultipleAllowedBlocks, template: [ [ 'core/button' ] ], templateInsertUpdatesSelection: true, orientation: layout?.orientation ?? 'horizontal', From ad4d8387ff2a346261819abc601b3e3e4e530ce1 Mon Sep 17 00:00:00 2001 From: adithya-naik Date: Tue, 5 May 2026 22:06:27 +0530 Subject: [PATCH 2/2] Simplify: Remove directInsert logic as Inserter now handles it internally --- packages/block-library/src/buttons/edit.js | 28 ++-------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/packages/block-library/src/buttons/edit.js b/packages/block-library/src/buttons/edit.js index 02ae7988b2ad17..527d497a0f1f48 100644 --- a/packages/block-library/src/buttons/edit.js +++ b/packages/block-library/src/buttons/edit.js @@ -6,13 +6,7 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { - useBlockProps, - useInnerBlocksProps, - store as blockEditorStore, -} from '@wordpress/block-editor'; -import { useSelect } from '@wordpress/data'; -import { store as blocksStore } from '@wordpress/blocks'; +import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; const DEFAULT_BLOCK = { name: 'core/button', @@ -29,7 +23,7 @@ const DEFAULT_BLOCK = { ], }; -function ButtonsEdit( { attributes, className, clientId } ) { +function ButtonsEdit( { attributes, className } ) { const { fontSize, layout, style } = attributes; const blockProps = useBlockProps( { className: clsx( className, { @@ -37,26 +31,8 @@ function ButtonsEdit( { attributes, className, clientId } ) { } ), } ); - const { hasButtonVariations, hasMultipleAllowedBlocks } = useSelect( - ( select ) => { - const buttonVariations = select( blocksStore ).getBlockVariations( - 'core/button', - 'inserter' - ); - const allowedBlocks = - select( blockEditorStore ).getAllowedBlocks( clientId ); - return { - hasButtonVariations: buttonVariations.length > 0, - hasMultipleAllowedBlocks: - allowedBlocks && allowedBlocks.length > 1, - }; - }, - [ clientId ] - ); - const innerBlocksProps = useInnerBlocksProps( blockProps, { defaultBlock: DEFAULT_BLOCK, - directInsert: ! hasButtonVariations && ! hasMultipleAllowedBlocks, template: [ [ 'core/button' ] ], templateInsertUpdatesSelection: true, orientation: layout?.orientation ?? 'horizontal',