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

[Navigation screen] Only show appender for the currently selected block #22998

Merged
merged 2 commits into from
Jun 9, 2020
Merged
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
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