Skip to content

Commit

Permalink
Layout: Always add semantic classes (#60668)
Browse files Browse the repository at this point in the history
* Layout: Always add semantic classes
* Default to undefined
* Feedback

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: davecpage <davecpage@git.wordpress.org>
  • Loading branch information
7 people authored and creativecoder committed May 2, 2024
1 parent 74f283f commit fd26a36
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ export function addAttribute( settings ) {
return settings;
}

function BlockWithLayoutStyles( { block: BlockListBlock, props } ) {
function BlockWithLayoutStyles( {
block: BlockListBlock,
props,
layoutClasses,
} ) {
const { name, attributes } = props;
const id = useInstanceId( BlockListBlock );
const { layout } = attributes;
Expand All @@ -348,7 +352,6 @@ function BlockWithLayoutStyles( { block: BlockListBlock, props } ) {
layout?.inherit || layout?.contentSize || layout?.wideSize
? { ...layout, type: 'constrained' }
: layout || defaultBlockLayout || {};
const layoutClasses = useLayoutClasses( attributes, name );

const { kebabCase } = unlock( componentsPrivateApis );
const selectorPrefix = `wp-container-${ kebabCase( name ) }-is-layout-`;
Expand Down Expand Up @@ -395,7 +398,9 @@ function BlockWithLayoutStyles( { block: BlockListBlock, props } ) {
*/
export const withLayoutStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const { name, attributes } = props;
const blockSupportsLayout = hasLayoutBlockSupport( props.name );
const layoutClasses = useLayoutClasses( attributes, name );
const shouldRenderLayoutStyles = useSelect(
( select ) => {
// The callback returns early to avoid block editor subscription.
Expand All @@ -410,11 +415,22 @@ export const withLayoutStyles = createHigherOrderComponent(
);

if ( ! shouldRenderLayoutStyles ) {
return <BlockListBlock { ...props } />;
return (
<BlockListBlock
{ ...props }
__unstableLayoutClassNames={
blockSupportsLayout ? layoutClasses : undefined
}
/>
);
}

return (
<BlockWithLayoutStyles block={ BlockListBlock } props={ props } />
<BlockWithLayoutStyles
block={ BlockListBlock }
props={ props }
layoutClasses={ layoutClasses }
/>
);
},
'withLayoutStyles'
Expand Down

0 comments on commit fd26a36

Please sign in to comment.