Skip to content

Commit

Permalink
Buttons Block: Show inserter if button have variations (WordPress#53498)
Browse files Browse the repository at this point in the history
  • Loading branch information
petitphp committed Sep 11, 2023
1 parent c10b0f6 commit 4e7c858
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -49,10 +50,18 @@ function ButtonsEdit( { attributes, className } ) {
return preferredStyleVariations?.value?.[ buttonBlockName ];
}, [] );

const hasButtonVariations = useSelect( ( select ) => {
const buttonVariations = select( blocksStore ).getBlockVariations(
buttonBlockName,
'inserter'
);
return buttonVariations.length > 0;
}, [] );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
defaultBlock: DEFAULT_BLOCK,
directInsert: true,
directInsert: ! hasButtonVariations,
template: [
[
buttonBlockName,
Expand Down

0 comments on commit 4e7c858

Please sign in to comment.