Skip to content

Commit

Permalink
Add variation default class name to the visual editor by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcafferkey committed Jun 11, 2024
1 parent c2fb616 commit 0a12f45
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,26 @@ function BlockListBlockProvider( props ) {
hasBlockSupport: _hasBlockSupport,
getActiveBlockVariation,
} = select( blocksStore );

const attributes = getBlockAttributes( clientId );
const { name: blockName, isValid } = blockWithoutAttributes;
const match = getActiveBlockVariation( blockName, attributes );
const blockType = getBlockType( blockName );
const { supportsLayout, __unstableIsPreviewMode: isPreviewMode } =
getSettings();
const hasLightBlockWrapper = blockType?.apiVersion > 1;
const defaultClassNames = [];
if ( hasLightBlockWrapper && blockName ) {
defaultClassNames.push( getBlockDefaultClassName( blockName ) );

if ( match && match?.name ) {
defaultClassNames.push(
getBlockDefaultClassName(
`${ blockName }/${ match.name }`
)
);
}
}
const previewContext = {
isPreviewMode,
blockWithoutAttributes,
Expand All @@ -610,9 +624,10 @@ function BlockListBlockProvider( props ) {
className: hasLightBlockWrapper
? attributes.className
: undefined,
defaultClassName: hasLightBlockWrapper
? getBlockDefaultClassName( blockName )
: undefined,
defaultClassName:
defaultClassNames.length > 0
? clsx( defaultClassNames )
: undefined,
blockTitle: blockType?.title,
};

Expand All @@ -625,7 +640,6 @@ function BlockListBlockProvider( props ) {
const _isSelected = isBlockSelected( clientId );
const canRemove = canRemoveBlock( clientId, rootClientId );
const canMove = canMoveBlock( clientId, rootClientId );
const match = getActiveBlockVariation( blockName, attributes );
const isMultiSelected = isBlockMultiSelected( clientId );
const checkDeep = true;
const isAncestorOfSelectedBlock = hasSelectedInnerBlock(
Expand Down

0 comments on commit 0a12f45

Please sign in to comment.