Skip to content

Commit 419d754

Browse files
authored
Don't render undefined classname in useBlockProps hook (#56923)
* Remove undefined classname in useBlockProps hook * Consider when block default classname is undefined
1 parent 6989045 commit 419d754

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

  • packages/block-editor/src/components/block-list/use-block-props

packages/block-editor/src/components/block-list/use-block-props/index.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,29 +172,32 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
172172
_isSelected && __unstableGetEditorMode() === 'edit'
173173
? getSelectedBlocksInitialCaretPosition()
174174
: undefined,
175-
classNames: classnames( {
176-
'is-selected': _isSelected,
177-
'is-highlighted': isBlockHighlighted( clientId ),
178-
'is-multi-selected': isMultiSelected,
179-
'is-partially-selected':
180-
isMultiSelected &&
181-
! __unstableIsFullySelected() &&
182-
! __unstableSelectionHasUnmergeableBlock(),
183-
'is-reusable': isReusableBlock( blockType ),
184-
'is-dragging': isBlockBeingDragged( clientId ),
185-
'has-child-selected': isAncestorOfSelectedBlock,
186-
'remove-outline': _isSelected && outlineMode && typing,
187-
'is-block-moving-mode': !! movingClientId,
188-
'can-insert-moving-block':
189-
movingClientId &&
190-
canInsertBlockType(
191-
getBlockName( movingClientId ),
192-
getBlockRootClientId( clientId )
193-
),
194-
[ attributes.className ]: hasLightBlockWrapper,
195-
[ getBlockDefaultClassName( blockName ) ]:
196-
hasLightBlockWrapper,
197-
} ),
175+
classNames: classnames(
176+
{
177+
'is-selected': _isSelected,
178+
'is-highlighted': isBlockHighlighted( clientId ),
179+
'is-multi-selected': isMultiSelected,
180+
'is-partially-selected':
181+
isMultiSelected &&
182+
! __unstableIsFullySelected() &&
183+
! __unstableSelectionHasUnmergeableBlock(),
184+
'is-reusable': isReusableBlock( blockType ),
185+
'is-dragging': isBlockBeingDragged( clientId ),
186+
'has-child-selected': isAncestorOfSelectedBlock,
187+
'remove-outline': _isSelected && outlineMode && typing,
188+
'is-block-moving-mode': !! movingClientId,
189+
'can-insert-moving-block':
190+
movingClientId &&
191+
canInsertBlockType(
192+
getBlockName( movingClientId ),
193+
getBlockRootClientId( clientId )
194+
),
195+
},
196+
hasLightBlockWrapper ? attributes.className : undefined,
197+
hasLightBlockWrapper
198+
? getBlockDefaultClassName( blockName )
199+
: undefined
200+
),
198201
};
199202
},
200203
[ clientId ]

0 commit comments

Comments
 (0)