Skip to content

Commit

Permalink
Show children of top level main container when in zoomed out view (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Dec 8, 2023
1 parent 55e84f0 commit 3522b1a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ function BlockSelectionButton( { clientId, rootClientId } ) {
<BlockTitle
clientId={ clientId }
maximumLength={ 35 }
context="list-view"
/>
</Button>
</FlexItem>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const defaultRenderToggle = ( {
blockTitle
);
} else if ( ! label && prioritizePatterns ) {
label = __( 'Add pattern' );
label = __( 'Add section' );
} else if ( ! label ) {
label = _x( 'Add block', 'Generic label for block inserter button' );
}
Expand Down
23 changes: 17 additions & 6 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ function ListViewBranch( props ) {
const parentBlockInformation = useBlockDisplayInformation( parentId );
const syncedBranch = isSyncedBranch || !! parentBlockInformation?.isSynced;

const canParentExpand = useSelect(
const { canParentExpand, getBlockById } = useSelect(
( select ) => {
if ( ! parentId ) {
return true;
}
return select( blockEditorStore ).canEditBlock( parentId );
const { canEditBlock, getBlockParents, getBlockName, getBlock } =
select( blockEditorStore );

return {
canParentExpand: canEditBlock( parentId ),
getBlocksParents: getBlockParents,
getName: getBlockName,
getBlockById: getBlock,
};
},
[ parentId ]
);
Expand All @@ -132,6 +137,10 @@ function ListViewBranch( props ) {
return (
<>
{ filteredBlocks.map( ( block, index ) => {
const isContentSection =
getBlockById( block.clientId )?.attributes?.tagName ===
'main';

const { clientId, innerBlocks } = block;

if ( index > 0 ) {
Expand All @@ -154,7 +163,8 @@ function ListViewBranch( props ) {
const hasNestedBlocks = !! innerBlocks?.length;

const shouldExpand =
hasNestedBlocks && shouldShowInnerBlocks
hasNestedBlocks &&
( shouldShowInnerBlocks || isContentSection )
? expandedState[ clientId ] ?? isExpanded
: undefined;

Expand Down Expand Up @@ -221,6 +231,7 @@ function ListViewBranch( props ) {
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
isSyncedBranch={ syncedBranch }
shouldShowInnerBlocks={ shouldShowInnerBlocks }
/>
) }
</AsyncModeProvider>
Expand Down
11 changes: 8 additions & 3 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2846,9 +2846,14 @@ export function __unstableHasActiveBlockOverlayActive( state, clientId ) {

// In zoom-out mode, the block overlay is always active for top level blocks.
if (
editorMode === 'zoom-out' &&
clientId &&
! getBlockRootClientId( state, clientId )
( editorMode === 'zoom-out' &&
clientId &&
! getBlockRootClientId( state, clientId ) &&
! getBlock( state, clientId )?.attributes?.tagName === 'main' ) ||
getBlockParents( state, clientId )?.find(
( parentId ) =>
getBlock( state, parentId )?.attributes?.tagName === 'main'
)
) {
return true;
}
Expand Down

0 comments on commit 3522b1a

Please sign in to comment.