Skip to content

Commit

Permalink
Fix fill
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 24, 2023
1 parent 9835e7f commit 4ffc496
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
10 changes: 4 additions & 6 deletions packages/block-editor/src/components/block-controls/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
*/
import groups from './groups';
import { useBlockEditContext } from '../block-edit/context';
import useDisplayBlockControls from '../use-display-block-controls';

export default function useBlockControlsFill( group, shareWithChildBlocks ) {
const isDisplayed = useDisplayBlockControls();
const { shouldDisplayControls } = useBlockEditContext();
const isParentDisplayed = shareWithChildBlocks && shouldDisplayControls;
const { shouldDisplayControls, shouldDisplayControlsWithinChildren } =
useBlockEditContext();

if ( isDisplayed ) {
if ( shouldDisplayControls ) {
return groups[ group ]?.Fill;
}
if ( isParentDisplayed ) {
if ( shareWithChildBlocks && shouldDisplayControlsWithinChildren ) {
return groups.parent.Fill;
}
return null;
Expand Down
10 changes: 9 additions & 1 deletion packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default function BlockEdit( props ) {
getBlockName,
isFirstMultiSelectedBlock,
getMultiSelectedBlockClientIds,
hasSelectedInnerBlock,
} = select( blockEditorStore );

if ( isFirstMultiSelectedBlock( clientId ) ) {
Expand All @@ -56,6 +55,14 @@ export default function BlockEdit( props ) {
);
}

return false;
},
[ clientId, isSelected, name ]
);
const shouldDisplayControlsWithinChildren = useSelect(
( select ) => {
const { getBlockName, hasSelectedInnerBlock } =
select( blockEditorStore );
return (
hasBlockSupport(
getBlockName( clientId ),
Expand All @@ -73,6 +80,7 @@ export default function BlockEdit( props ) {
layout: layoutSupport ? layout : null,
__unstableLayoutClassNames,
shouldDisplayControls,
shouldDisplayControlsWithinChildren,
};
return (
<BlockEditContextProvider
Expand Down
7 changes: 5 additions & 2 deletions packages/block-editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ function AlignControls( props ) {
*/
export const withToolbarControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { shouldDisplayControls, shouldDisplayControlsWithinChildren } =
useBlockEditContext();
return (
<>
{ useBlockEditContext().shouldDisplayControls &&
!! getBlockSupport( props.name, 'align' ) && (
{ ( shouldDisplayControls ||
shouldDisplayControlsWithinChildren ) &&
hasBlockSupport( props.name, 'align' ) && (
<AlignControls { ...props } />
) }
<BlockEdit { ...props } />
Expand Down

0 comments on commit 4ffc496

Please sign in to comment.