-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Simplify the way we create a link UI control in the offcanvas editor #46744
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
Conversation
|
Size Change: +120 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
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.
Update
See my next review.
Thanks for working on this one. I started on exactly the same thing before Xmas and it seems you've hit the same bug as I did...
Screen.Capture.on.2023-01-03.at.14-00-47.mp4
Basically despite the fact that you've "committed" your changes the Link UI can reopen for the last inserted block under certain conditions.
We probably need to track the "current" item and then check whether that item has been committed. However that would require storing the data in a component that won't be unmounted, or within global application state.
| position="bottom right" | ||
| isAppender={ true } | ||
| selectBlockOnInsert={ false } | ||
| onSelectOrClose={ maybeSetInsertedBlockOnInsertion } |
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.
If we get rid of this perhaps we can also revert the changes I previously made to Inserter. If and when we merge this PR I can make a followup.
packages/block-editor/src/components/off-canvas-editor/block-contents.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/off-canvas-editor/block-contents.js
Show resolved
Hide resolved
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 worked on the problem a little and I reasoned that the condition for showing the Link UI was based on whether the current block already has a link or not. If it doesn't then we show the UI otherwise it should remain hidden (as per trunk).
I decided to use the id attribute of the block as a proxy for the concept of "has a link value" (although we could just as easily use url) and used that to conditionalise the call to setIsLinkUIOpen(true) in the effect.
This fixes the issue and I believe we are now ready to merge.
What?
This is a small refactor as suggested in #46503, which should simplify the code that creates the LinkUI.
Why?
Simple code is easier to understand and maintain. This will also allow us to display the link UI alongside the relevant block when we are inserting a submenu at a different point in the tree (see #46582).
How?
Testing Instructions

3. Attempt to add a block using the block inserter 4. Check that the block is added correctly and that the inserter closes when you have selected a link.Testing Instructions for Keyboard
As above
Co-authored-by: Dave Smith [email protected]