Skip to content

Commit

Permalink
[Navigation screen] Only show appender for the currently selected blo…
Browse files Browse the repository at this point in the history
…ck (#22998)

* Only show appender for the currently selected block

* Don't display an empty branch
  • Loading branch information
adamziel authored Jun 9, 2020
1 parent 1aff047 commit 47f4796
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/block-editor/src/components/block-navigation/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@ export default function BlockNavigationBranch( props ) {

const isTreeRoot = ! parentBlockClientId;
const filteredBlocks = compact( blocks );
const itemHasAppender = ( parentClientId ) =>
showAppender &&
! isTreeRoot &&
selectedBlockClientId === parentClientId;
const hasAppender = itemHasAppender( parentBlockClientId );
// Add +1 to the rowCount to take the block appender into account.
const rowCount = showAppender
const rowCount = hasAppender
? filteredBlocks.length + 1
: filteredBlocks.length;
const hasAppender =
showAppender && filteredBlocks.length > 0 && ! isTreeRoot;
const appenderPosition = rowCount;

return (
<>
{ map( filteredBlocks, ( block, index ) => {
const { clientId, innerBlocks } = block;
const hasNestedBlocks =
showNestedBlocks && !! innerBlocks && !! innerBlocks.length;
const position = index + 1;
const isLastRowAtLevel = rowCount === position;
const updatedTerminatedLevels = isLastRowAtLevel
? [ ...terminatedLevels, level ]
: terminatedLevels;
const updatedPath = [ ...path, position ];
const hasNestedBlocks =
showNestedBlocks && !! innerBlocks && !! innerBlocks.length;
const hasNestedAppender = itemHasAppender( clientId );

return (
<Fragment key={ clientId }>
Expand All @@ -64,7 +68,7 @@ export default function BlockNavigationBranch( props ) {
terminatedLevels={ terminatedLevels }
path={ updatedPath }
/>
{ hasNestedBlocks && (
{ ( hasNestedBlocks || hasNestedAppender ) && (
<BlockNavigationBranch
blocks={ innerBlocks }
selectedBlockClientId={ selectedBlockClientId }
Expand Down

0 comments on commit 47f4796

Please sign in to comment.