Skip to content

Commit

Permalink
Block Editor: Try to absorb parent block toolbar controls
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Aug 9, 2021
1 parent 64fadb5 commit 8d8f561
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/block-controls/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export default function BlockControlsFill( {
group = 'default',
controls,
children,
__experimentalExposeToChildren = false,
} ) {
if ( ! useDisplayBlockControls() ) {
if ( ! useDisplayBlockControls( { __experimentalExposeToChildren } ) ) {
return null;
}
const Fill = groups[ group ].Fill;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@ import { useSelect } from '@wordpress/data';
import { useBlockEditContext } from '../block-edit/context';
import { store as blockEditorStore } from '../../store';

export default function useDisplayBlockControls() {
export default function useDisplayBlockControls( {
__experimentalExposeToChildren = false,
} = {} ) {
const { isSelected, clientId, name } = useBlockEditContext();
const isFirstAndSameTypeMultiSelected = useSelect(
const isActive = useSelect(
( select ) => {
// Don't bother checking, see OR statement below.
if ( isSelected ) {
return;
return true;
}

const {
getBlockName,
isFirstMultiSelectedBlock,
getMultiSelectedBlockClientIds,
hasSelectedInnerBlock,
} = select( blockEditorStore );

if ( ! isFirstMultiSelectedBlock( clientId ) ) {
return false;
if ( isFirstMultiSelectedBlock( clientId ) ) {
return getMultiSelectedBlockClientIds().every(
( id ) => getBlockName( id ) === name
);
}
if ( __experimentalExposeToChildren ) {
return hasSelectedInnerBlock( clientId );
}

return getMultiSelectedBlockClientIds().every(
( id ) => getBlockName( id ) === name
);
return false;
},
[ clientId, isSelected, name ]
);

return isSelected || isFirstAndSameTypeMultiSelected;
return isActive;
}
3 changes: 2 additions & 1 deletion packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function ButtonsEdit( {
],
],
orientation,
__experimentalCaptureToolbars: true,
__experimentalLayout: LAYOUT,
templateInsertUpdatesSelection: true,
} );
Expand All @@ -70,7 +71,7 @@ function ButtonsEdit( {

return (
<>
<BlockControls group="block">
<BlockControls group="block" __experimentalExposeToChildren>
<JustifyContentControl
allowedControls={ justifyControls }
value={ contentJustification }
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function SocialLinksEdit( props ) {
const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
orientation: 'horizontal',
__experimentalCaptureToolbars: true,
placeholder: isSelected ? SelectedSocialPlaceholder : SocialPlaceholder,
templateLock: false,
__experimentalAppenderTagName: 'li',
Expand All @@ -111,7 +112,7 @@ export function SocialLinksEdit( props ) {

return (
<Fragment>
<BlockControls group="block">
<BlockControls group="block" __experimentalExposeToChildren>
<JustifyContentControl
allowedControls={ [
'left',
Expand Down

0 comments on commit 8d8f561

Please sign in to comment.