-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Nav offcanvas - handle non-direct insert block inserter #46503
Conversation
Size Change: +289 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
const firstBlock = | ||
Array.isArray( blocks ) && blocks?.length | ||
? blocks[ 0 ] | ||
: blocks; |
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.
I'm not sure whether this is necessary. Can anyone think of a scenario when onSelect
would be called by the quick inserter with an array of blocks rather than just a single block?
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.
Now that #46531 has landed I may refactor this callback implementation in a follow up.
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.
The contact form in Jetpack has blocks inside it for each field. I'm not sure if they get appended as an array though.
}; | ||
|
||
const maybeSetInsertedBlockOnInsertion = ( _insertedBlock ) => { | ||
if ( ! _insertedBlock?.clientId ) { |
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.
The Inserter can be closed with no block selected. In this case the callback is still closed but no block is passed to the callback. This is the guard.
setInsertedBlock( insertedBlockId ); | ||
} } | ||
onSelectOrClose={ maybeSetInsertedBlockOnInsertion } | ||
__experimentalIsQuick |
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 triggers the smaller inserter.
@@ -39,6 +39,7 @@ function useInsertionPoint( { | |||
isAppender, | |||
onSelect, | |||
shouldFocusBlock = true, | |||
selectBlockOnInsert = true, |
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.
Here I'm aiming to ensure backwards compat by setting the default to the same as the hardcoded original value.
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.
Should we make a comment for the future?
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.
I don't know. We could but I'm thinking someone coming here and flipping that value would think twice before changing the component default.s
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 testing good for me, I couldn't get it to break. It's a much better experience, thank you!
Unlike in the video, when I insert a custom link after having inserted another block type, the inspector opens on the canvas, not in the sidebar. |
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.
Looking good now
* Pass blocks from block inserter to custom appender callback * Allow only blocks which support Link UI to trigger it’s rendering on insertion * Allow Link UI for all supporting blocks * Extract clearly named function to improve comprehension * Allow for programmatic disabling of selecting block on insertion via Quick Inserter * Fix stray false * Provide correct default to ensure behaviour is backwards compatible * Always pass selectBlockOnInsert
What?
Handles the offcanvas UX block insertion flow in the Nav offcanvas experiment when the Nav block contains blocks other than
core/navigation-link
thus triggering the "full" inserter UI (i.e. no direct-insert). The flow becomes:Browse
in the quick inserter triggers the full block inserter and closes the off canvas 🤔Closes #46203
Why?
The two-step insertion behaviour is what already happens in the editor canvas when the Nav block has non-
core/navigation-link
blocks in it. Therefore we need to handle the same use case in the offcanvas.Having a two step process affords the user greater control over the type of block they wish to insert into their Navigation.
Whilst this does introduce some friction for those users wishing simply to add links, it does afford full power to insert any of the block types without having to rely on obfuscated/convoluted UX such as:
How?
The key changes are:
__experimentalIsQuick
to the<Inserter>
component to trigger the<QuickInserter>
style (as per block canvas)selectBlockOnInsert
and conditionally set the 4th argument of calls toinsertBlock
within the hooks consumed by the<QuickInserter>
onSelectOrClose
and have the<QuickInserter>
call this when defined with the blocks that were inserted (if any).Future plans
In the future I imagine we can refactor some of this callback code around the Link UI:
add a reducer to keep track of the inserted blocks as a flattened arraysee Add new selector getLastInsertedBlockClientId #46531add a selector to retrieve the most recently inserted block (e.g.see Add new selector getLastInsertedBlockClientId #46531getLastInsertedBlock()
)ListViewBlockContents
componentgetLastInsertedBlock
selectorTesting Instructions
core/navigation-link
this should work as pertrunk
and immediately insert the block and show the Link UI. That is expected.Transforms
in the Link UI to add a social icons block.Testing Instructions for Keyboard
Screenshots or screencast
Screen.Capture.on.2022-12-13.at.13-31-35.mp4