Skip to content
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
16 changes: 13 additions & 3 deletions 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 @@ -42,17 +43,26 @@ function ButtonsEdit( { attributes, className } ) {
'has-custom-font-size': fontSize || style?.typography?.fontSize,
} ),
} );
const preferredStyle = useSelect( ( select ) => {
const { preferredStyle, hasButtonVariations } = useSelect( ( select ) => {
const preferredStyleVariations =
select( blockEditorStore ).getSettings()
.__experimentalPreferredStyleVariations;
return preferredStyleVariations?.value?.[ buttonBlockName ];
const buttonVariations = select( blocksStore ).getBlockVariations(
buttonBlockName,
'inserter'
);
return {
preferredStyle:
preferredStyleVariations?.value?.[ buttonBlockName ],
hasButtonVariations: buttonVariations.length > 0,
};
}, [] );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
defaultBlock: DEFAULT_BLOCK,
directInsert: true,
// This check should be handled by the `Inserter` internally to be consistent across all blocks that use it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this considered a follow-up? What prevented us from actually implementing this solution?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood it to be for a follow-up.

What prevented us from actually implementing this solution?

I suppose nothing besides someone putting in the effort. I've taken a closer look and the logic is actually already there. It seems the Buttons block was working as in this PR before #37905. In that PR directInsert: true was added and which forces it even when there are variations. I think I found a way to reconcile this.

directInsert: ! hasButtonVariations,
template: [
[
buttonBlockName,
Expand Down