-
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
Refactor <BlockToolbar /> #56335
Refactor <BlockToolbar /> #56335
Conversation
Size Change: -136 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
packages/block-editor/src/components/block-tools/block-toolbar-popover.js
Outdated
Show resolved
Hide resolved
@@ -192,7 +192,7 @@ export default function BlockTools( { | |||
{ /* Even if the toolbar is fixed, the block popover is still | |||
needed for navigation and zoom-out mode. */ } | |||
{ ! showEmptyBlockSideInserter && hasSelectedBlock && ( | |||
<SelectedBlockTools | |||
<BlockToolbarPopover | |||
__unstableContentRef={ __unstableContentRef } | |||
clientId={ 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.
Is clientId useless here?
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.
It is used within the component, but we could fetch it from within the <BlockToolbarPopover />
instead if you'd like. I had it passed it because it was already available, but if you prefer letting <BlockToolbarPopover />
and <EmptyBlockInserter />
handle them on their own, that's fine with me!
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.
Nice work here, it seems like a nice cleanup. You're saying the old component was not really usable unless you put it within NavigableToolbar, what happens now if this new component is inserted within NavigableToolbar (double NavigableToolbar) is that bad? is it acceptable compatibility? It seems fine to me. I also only expect third-party block editors to be using this component.
Flaky tests detected in 58afab9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7132589444
|
The 'should hide the toolbar when typing' test is failing, but it's because it's checking for the toolbar to be |
6297c94
to
ede3596
Compare
@youknowriad Here's a direction for the block toolbar refactor. The only prop that is added to the BlockToolbar is |
There was a regression in the typing metric due to the BlockToolbar doing some processing on each keystroke.
f3b5f4e
to
528665a
Compare
I believe I've addressed all feedback. Ready for another review! |
The naming was inconsistent and confusing. showBlockToolbar being true did not mean the block toolbar would show. Similarly for showBreadcrumb. Refactored so if showBlockToolbar is true, it will show the block toolbar popover.
Addresses #56046
What?
<BlockToolbar />
is not usable for the top toolbar in its current form as intended. This refactors and its implementation so it can be used directly in the top toolbar from #55787.Why?
The
<BlockToolbar />
needs the<BlockContextualToolbar />
wrapper to accomplish our usage within Gutenberg. If we make<BlockToolbar />
useful on its own, then we can use it directly instead of relying on a private export of<BlockContextualToolbar />
in the top toolbar headers.How?
<BlockContextualToolbar />
into<BlockToolbar />
. This brings all the necessary functionality for<BlockToolbar />
to be used, mainly by wrapping it in a<NavigableToolbar />
.<BlockContextualToolbar />
. This is no longer needed, and was originally intended for Contextual to mean Popover.<BlockContextualToobar />
in edit-site, edit-post, edit-widget, etc headers with<BlockToolbar />
<SelectedBlockTools />
becomes<BlockToolbarPopover />
to better reflect its purpose.<PrivateBlockToolbar />
with new props of__experimentalInitialIndex
,__experimentalOnIndexChange
, andfocusOnMount
.<BlockToolbar />
from<PrivateBlockToolbar />
with locked__experimentalInitialIndex
,__experimentalOnIndexChange
, andfocusOnMount
asundefined
. Public API props arehideDragHandles
andvariant
with a default ofunstyled
.isFixed
from the<BlockToolbar />
. The styles of the current small-screen fixed toolbar will become the default. The popover and top toolbars will have its own CSS overrides applied.<BlockToolbarPopover />
and<BlockBreadcrumbPopover />
into separate components for simplicity.<BlockToolbar />
on your own."Follow-up
block-editor-contextual-block-toolbar
? contextual was intended to mean "floating near the block," but contextual can also mean "context related to the selected blocks," so maybe it's better to leave it as is rather than break potential CSS implementations? Ideally, this would be theblock-editor-block-toolbar
class name and the nested div within it could be removed.<BlockToolbar />
made me reconsider how to get the__experimentalInitialIndex
,__experimentalOnIndexChange
, andfocusOnMount
handled from<NavigableToolbar />
. These are used by the block popover to focus the last focused index of the toolbar when using thealt + f10
shortcut. And the reason they are needed is because the block toolbar unmounts onshouldShowContextualToolbar
. But, if instead of unmounting it, we hide it with CSS, then we get all of the initial index and focusOnMount stuff for free since it's already handled by the roving tabindex. Those props can be removed from the code entirely. It also simplifies how the shortcut is handled.hideDragHandle
in favor ofshowDragHandle = false
to default to not showing the drag handle since it's only used on the popover.Testing Instructions
trunk
Testing Instructions for Keyboard
Dev Notes
<BlockToolbar />
directly and it was wrapped in a<NavigableToolbar />
component, remove the<NavigableToolbar />
wrapper.<BlockTools />
will not render any<BlockToolbar />
. The<BlockToolbar />
will needed to be added manually.