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 committed Apr 15, 2024
1 parent 741aaab commit 26e35c7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ function BlockWithLayoutStyles( {
block: BlockListBlock,
props,
blockGapSupport,
layoutClasses,
} ) {
const { name, attributes } = props;
const id = useInstanceId( BlockListBlock );
Expand All @@ -369,7 +370,6 @@ function BlockWithLayoutStyles( {
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 @@ -415,8 +415,9 @@ function BlockWithLayoutStyles( {
*/
export const withLayoutStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const { clientId, name } = props;
const { clientId, name, attributes } = props;
const blockSupportsLayout = hasLayoutBlockSupport( name );
const layoutClasses = useLayoutClasses( attributes, name );
const extraProps = useSelect(
( select ) => {
// The callback returns early to avoid block editor subscription.
Expand Down Expand Up @@ -444,13 +445,21 @@ export const withLayoutStyles = createHigherOrderComponent(
);

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

return (
<BlockWithLayoutStyles
block={ BlockListBlock }
props={ props }
layoutClasses={ layoutClasses }
{ ...extraProps }
/>
);
Expand Down

0 comments on commit 26e35c7

Please sign in to comment.