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: Try always showing appender even when child is selected. #37637

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function Navigation( {
hasSubmenuIndicatorSetting = true,
hasColorSettings = true,
customPlaceholder: CustomPlaceholder = null,
customAppender: CustomAppender = null,
} ) {
const {
openSubmenusOnClick,
Expand Down Expand Up @@ -696,7 +695,6 @@ function Navigation( {
<NavigationInnerBlocks
isVisible={ ! isPlaceholderShown }
clientId={ clientId }
appender={ CustomAppender }
hasCustomPlaceholder={
!! CustomPlaceholder
}
Expand Down
19 changes: 16 additions & 3 deletions packages/block-library/src/navigation/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useEntityBlockEditor } from '@wordpress/core-data';
import {
useInnerBlocksProps,
InnerBlocks,
__experimentalBlockContentOverlay as BlockContentOverlay,
store as blockEditorStore,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -39,7 +40,6 @@ const LAYOUT = {
export default function NavigationInnerBlocks( {
isVisible,
clientId,
appender: CustomAppender,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is still being used by the navigation screen; might be worth preserving the option of passing in a custom appender.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to best address this feedback item, but feel free to push to the branch if you like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with it and realised the previous code wasn't working on the nav editor (probably due to the changes we made to the block late last year) so I just removed the prop being passed to NavigationInnerBlocks altogether.

hasCustomPlaceholder,
orientation,
} ) {
Expand Down Expand Up @@ -95,7 +95,6 @@ export default function NavigationInnerBlocks( {
const parentOrChildHasSelection =
isSelected ||
( isImmediateParentOfSelectedBlock && ! selectedBlockHasDescendants );
const appender = isVisible && parentOrChildHasSelection ? undefined : false;

const placeholder = useMemo( () => <PlaceholderPreview />, [] );

Expand All @@ -111,7 +110,21 @@ export default function NavigationInnerBlocks( {
__experimentalDefaultBlock: DEFAULT_BLOCK,
__experimentalDirectInsert: shouldDirectInsert,
orientation,
renderAppender: CustomAppender || appender,

// As an exception to other blocks which feature nesting, show
// the block appender even when a child block is selected.
// This should be a temporary fix, to be replaced by improvements to
// the sibling inserter.
// See https://github.com/WordPress/gutenberg/issues/37572.
renderAppender:
isSelected ||
( isImmediateParentOfSelectedBlock &&
! selectedBlockHasDescendants ) ||
// Show the appender while dragging to allow inserting element between item and the appender.
parentOrChildHasSelection
? InnerBlocks.ButtonBlockAppender
: false,

// Template lock set to false here so that the Nav
// Block on the experimental menus screen does not
// inherit templateLock={ 'all' }.
Expand Down
19 changes: 18 additions & 1 deletion packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,25 @@ $color-control-label-height: 20px;
}
}

// Override inner padding on default appender.
// This should be a temporary fix, to be replaced by improvements to
// the sibling inserter.
// See https://github.com/WordPress/gutenberg/issues/37572.
.wp-block-navigation .block-editor-button-block-appender {
justify-content: flex-start;
background-color: $gray-900;
color: $white;

// This needs specificity to override an inherited padding.
// That source padding in turn has high specificity to protect
// from theme CSS bleed.
&.block-editor-button-block-appender.block-editor-button-block-appender {
padding: 0;
}
}

.wp-block-navigation .wp-block .wp-block .block-editor-button-block-appender {
background-color: transparent;
color: $gray-900;
}


Expand Down