Skip to content

Commit

Permalink
Fix up output so that position classes are applied to the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Oct 27, 2022
1 parent d71171b commit 81ea70e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function gutenberg_get_classnames_from_last_tag( $html ) {
$last_classnames = $tags->get_attribute( 'class' );
}

return $last_classnames;
return (string) $last_classnames;
}

/**
Expand Down Expand Up @@ -445,7 +445,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$content->add_class( implode( ' ', $class_names ) );
}

return $content;
return (string) $content;
}

// Register the block support. (overrides core one).
Expand Down Expand Up @@ -559,7 +559,7 @@ function gutenberg_render_layout_position_support( $block_content, $block ) {
$content = new WP_HTML_Tag_Processor( $block_content );
$content->next_tag();
$content->add_class( $class_name );
return $content;
return (string) $content;
}
return $block_content;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,18 @@ export const withLayoutStyles = createHigherOrderComponent(
}

// Attach a `wp-container-` id-based class name as well as a layout class name such as `is-layout-flex`.
const className = classnames(
props?.className,
const combinedLayoutClassNames = classnames(
{
[ `wp-container-${ id }` ]: shouldRenderLayoutStyles && !! css, // Only attach a container class if there is generated CSS to be attached.
[ `wp-container-${ positionId }` ]:
shouldRenderLayoutStyles && !! positionCss, // Use separate container class for position styles in prep for layout styles moving to inner wrapper in: https://github.com/WordPress/gutenberg/pull/44600
},
layoutClasses
);

const wrapperClassNames = classnames( props?.className, {
[ `wp-container-${ positionId }` ]:
shouldRenderLayoutStyles && !! positionCss, // Use separate container class for position styles in prep for layout styles moving to inner wrapper in: https://github.com/WordPress/gutenberg/pull/44600
} );

return (
<>
{ shouldRenderLayoutStyles &&
Expand All @@ -430,7 +432,8 @@ export const withLayoutStyles = createHigherOrderComponent(
) }
<BlockListBlock
{ ...props }
__unstableLayoutClassNames={ className }
className={ wrapperClassNames }
__unstableLayoutClassNames={ combinedLayoutClassNames }
/>
</>
);
Expand Down

0 comments on commit 81ea70e

Please sign in to comment.