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

Fix alligned blocks #32454

Merged
merged 3 commits into from
Jun 7, 2021
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
1 change: 1 addition & 0 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function BlockListBlock( {
clientId,
className,
wrapperProps: omit( wrapperProps, [ 'data-align' ] ),
isAligned,
};
const memoizedValue = useMemo( () => value, Object.values( value ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const BLOCK_ANIMATION_THRESHOLD = 200;
* @return {Object} Props to pass to the element to mark as a block.
*/
export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
const { clientId, className, wrapperProps = {} } = useContext(
const { clientId, className, wrapperProps = {}, isAligned } = useContext(
BlockListBlockContext
);
const {
Expand Down Expand Up @@ -141,7 +141,9 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
'data-title': blockTitle,
className: classnames(
// The wp-block className is important for editor styles.
'wp-block block-editor-block-list__block',
classnames( 'block-editor-block-list__block', {
'wp-block': ! isAligned,
} ),
className,
props.className,
wrapperProps.className,
Expand Down
4 changes: 1 addition & 3 deletions packages/block-editor/src/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Consider the block appender to be a child block of its own, which also has
// this class.
const BLOCK_SELECTOR = '.wp-block';
const BLOCK_SELECTOR = '.block-editor-block-list__block';

/**
* Returns true if two elements are contained within the same block.
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/navigation/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,15 @@ export default compose( [
const selectedBlockHasDescendants = !! getClientIdsOfDescendants( [
selectedBlockId,
] )?.length;

return {
isImmediateParentOfSelectedBlock,
selectedBlockHasDescendants,
hasExistingNavItems: !! innerBlocks.length,

// This prop is already available but computing it here ensures it's
// fresh compared to isImmediateParentOfSelectedBlock
isSelected: selectedBlockId === clientId,
};
} ),
withDispatch( ( dispatch, { clientId } ) => {
Expand Down