-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add appender to Block Navigator #18100
Changes from all commits
a890b5c
519c4af
6f817bb
85eaa1f
bd8fb2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { create, getTextContent } from '@wordpress/rich-text'; | |
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
import ButtonBlockAppender from '../button-block-appender'; | ||
|
||
/** | ||
* Get the block display name, if it has one, or the block title if it doesn't. | ||
|
@@ -43,8 +44,14 @@ export default function BlockNavigationList( { | |
blocks, | ||
selectedBlockClientId, | ||
selectBlock, | ||
showAppender, | ||
|
||
// Internal use only. | ||
showNestedBlocks, | ||
parentBlockClientId, | ||
} ) { | ||
const shouldShowAppender = showAppender && !! parentBlockClientId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had some ideas about improving the logic in this component around showing the appender. At the moment it shows the appender for any block that has childBlocks. An improvement might be:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Showing it only if it has child blocks (which is the equivalent of showing it only at the end of inner block areas) seems the correct way to me. The fact it adds a block immediately (the parent only supports a single child) or opens a full inserter should be irrelevant for the navigator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so happy with a popover in a modal? I can look into getting that working. Cheers for the quick feedback. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, though since we are going to enable this only within navigation menu initially, which only supports a single child, it should affect things much. |
||
|
||
return ( | ||
/* | ||
* Disable reason: The `list` ARIA role is redundant but | ||
|
@@ -75,12 +82,24 @@ export default function BlockNavigationList( { | |
blocks={ block.innerBlocks } | ||
selectedBlockClientId={ selectedBlockClientId } | ||
selectBlock={ selectBlock } | ||
parentBlockClientId={ block.clientId } | ||
showAppender={ showAppender } | ||
showNestedBlocks | ||
/> | ||
) } | ||
</li> | ||
); | ||
} ) } | ||
{ shouldShowAppender && ( | ||
<li> | ||
<div className="editor-block-navigation__item block-editor-block-navigation__item"> | ||
<ButtonBlockAppender | ||
rootClientId={ parentBlockClientId } | ||
__experimentalSelectBlockOnInsert={ false } | ||
/> | ||
</div> | ||
</li> | ||
) } | ||
</ul> | ||
/* eslint-enable jsx-a11y/no-redundant-roles */ | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,13 @@ import { _x, sprintf } from '@wordpress/i18n'; | |
import BlockDropZone from '../block-drop-zone'; | ||
import Inserter from '../inserter'; | ||
|
||
function ButtonBlockAppender( { rootClientId, className } ) { | ||
function ButtonBlockAppender( { rootClientId, className, __experimentalSelectBlockOnInsert: selectBlockOnInsert } ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The argument that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return ( | ||
<> | ||
<BlockDropZone rootClientId={ rootClientId } /> | ||
<Inserter | ||
rootClientId={ rootClientId } | ||
__experimentalSelectBlockOnInsert={ selectBlockOnInsert } | ||
renderToggle={ ( { onToggle, disabled, isOpen, blockTitle, hasSingleBlockType } ) => { | ||
let label; | ||
if ( hasSingleBlockType ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clever and made me think about how I'd love to see props grouped into
// Public
and//Private
for all our components. I'm always finding it tough to figure out whether a prop is public or e.g. added viawithSelect
.(Just a thought—nothing to do with this PR!)