Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block: move align wrapper out of Block element #23089

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions packages/block-editor/src/components/block-list/block-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const BlockComponent = forwardRef(
'core/block-editor'
);
const fallbackRef = useRef();
const isAligned = wrapperProps && !! wrapperProps[ 'data-align' ];
wrapper = wrapper || fallbackRef;

// Provide the selected node, or the first and last nodes of a multi-
Expand Down Expand Up @@ -191,7 +190,7 @@ const BlockComponent = forwardRef(
mode === 'html' && ! __unstableIsHtml ? '-visual' : '';
const blockElementId = `block-${ clientId }${ htmlSuffix }`;

const blockWrapper = (
return (
<TagName
// Overrideable props.
aria-label={ blockLabel }
Expand All @@ -203,8 +202,7 @@ const BlockComponent = forwardRef(
className={ classnames(
className,
props.className,
wrapperProps && wrapperProps.className,
! isAligned && 'wp-block'
wrapperProps && wrapperProps.className
) }
data-block={ clientId }
data-type={ name }
Expand All @@ -222,21 +220,6 @@ const BlockComponent = forwardRef(
{ children }
</TagName>
);

// For aligned blocks, provide a wrapper element so the block can be
// positioned relative to the block column.
if ( isAligned ) {
const alignmentWrapperProps = {
'data-align': wrapperProps[ 'data-align' ],
};
return (
<div className="wp-block" { ...alignmentWrapperProps }>
{ blockWrapper }
</div>
);
}

return blockWrapper;
}
);

Expand Down
15 changes: 15 additions & 0 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function BlockListBlock( {
? getBlockDefaultClassName( name )
: null;
const customClassName = lightBlockWrapper ? attributes.className : null;
const isAligned = wrapperProps && !! wrapperProps[ 'data-align' ];

// The wp-block className is important for editor styles.
// Generate the wrapper class names handling the different states of the
Expand All @@ -116,6 +117,7 @@ function BlockListBlock( {
customClassName,
'block-editor-block-list__block',
{
'wp-block': ! isAligned,
'has-warning': ! isValid || !! hasError || isUnregisteredBlock,
'is-selected': isSelected,
'is-highlighted': isHighlighted,
Expand Down Expand Up @@ -152,6 +154,19 @@ function BlockListBlock( {
/>
);

// For aligned blocks, provide a wrapper element so the block can be
// positioned relative to the block column.
if ( isAligned ) {
const alignmentWrapperProps = {
'data-align': wrapperProps[ 'data-align' ],
};
blockEdit = (
<div className="wp-block" { ...alignmentWrapperProps }>
{ blockEdit }
</div>
);
}

if ( mode !== 'visual' ) {
blockEdit = <div style={ { display: 'none' } }>{ blockEdit }</div>;
}
Expand Down