-
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
Remove block switcher from header, add to multi block controls #7891
Conversation
aria-label={ __( 'Block Toolbar' ) } | ||
key="toolbar" | ||
> | ||
<BlockSwitcher uids={ multiSelectedBlockUids } /> |
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 think a more appropriate place would be to move to the BlockToolbar
component which will make it appear at the right position depending on the preference Fix toolbar to top
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.
Done! This required that the BlockToolbar
became aware of multi-block selection, but it cut down on the repeated toolbars, and is a good point to insert multi-block toolbar controls :)
@@ -34,7 +33,6 @@ function HeaderToolbar( { hasFixedToolbar, isLargeViewport } ) { | |||
<EditorHistoryUndo /> | |||
<EditorHistoryRedo /> | |||
<TableOfContents /> | |||
<MultiBlocksSwitcher /> |
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 wonder if this MultiBlocksSwitcher
is already handling showing the switcher only for multi selection.
We should:
- Delete this component since you duplicated its logic in
block-toolbar
- Or Use it in
block-toolbar
directly
function BlockToolbar( { block, mode } ) { | ||
if ( ! block || ! block.isValid || mode !== 'visual' ) { | ||
function BlockToolbar( { block, mode, selectedBlockUIDs } ) { | ||
if ( selectedBlockUIDs.length < 2 && ( ! block || ! block.isValid || 'visual' !== mode ) ) { |
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 also render nothing if the
selectedBlockUIDs
is empty? - Instead of passing the whole
block
object. It seems we can just get theisValid
flag instead as a prop that way this component will only rerender if the flag changes and not other block properties (performance tip)
return null; | ||
} | ||
|
||
return ( | ||
<div className="editor-block-toolbar"> | ||
<BlockSwitcher uids={ [ block.uid ] } /> | ||
<BlockSwitcher uids={ selectedBlockUIDs.length > 1 ? selectedBlockUIDs : [ block.uid ] } /> |
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 wonder if we can't normalize this selectedBlockUIDs
and block
prop with a unique selectedBlockUIDs
which would contain the selected blocks (multi-selection or not)
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.
That would make things a lot cleaner. Thanks!
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.
👍 Thanks for the updates
return null; | ||
} | ||
|
||
return ( | ||
<div className="editor-block-toolbar"> | ||
<BlockSwitcher uids={ [ block.uid ] } /> | ||
<BlockSwitcher uids={ blockUIDs } /> | ||
<BlockControls.Slot /> |
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 wonder if it makes sense to keep the slots in case we want to show multi-selection controls or something like that in 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.
Yes, we do, and I'm working on that next week in another PR :) So I'll be rebasing to use these changes in that PR
Description
Removed the block switcher from the header, and made it appear when selecting multiple blocks.
How has this been tested?
Select multiple blocks and check the switcher is there.