-
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
Try a fixed toolbar in the navigation page #21340
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6fe780f
Render the block toolbar popover slot in the correct place
talldan ae996a8
Try fixed toolbar in navigation page
talldan a410a8b
Clear block selection when changing menus
talldan a45945c
Fix toolbar styles
talldan 16cf957
Render the Popover.Slot for the block toolbar to ensure navigation mo…
talldan d8be3a9
Hide the fixed navigation menu page toolbar when entering navigation …
talldan a796f3c
Fix issue with navigation structure panel being always initially closed
talldan aff58f7
Do not show a Block Toolbar when the selected block does not exist
talldan a56ef6e
Account for multi-selections when determining whether a block is sele…
talldan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/edit-navigation/src/components/menu-editor/block-editor-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
BlockList, | ||
BlockToolbar, | ||
NavigableToolbar, | ||
ObserveTyping, | ||
WritingFlow, | ||
} from '@wordpress/block-editor'; | ||
import { Button, Panel, PanelBody, Popover } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export default function BlockEditorPanel( { saveBlocks } ) { | ||
const { isNavigationModeActive, hasSelectedBlock } = useSelect( | ||
( select ) => { | ||
const { | ||
isNavigationMode, | ||
getBlockSelectionStart, | ||
getBlock, | ||
} = select( 'core/block-editor' ); | ||
|
||
const selectionStartClientId = getBlockSelectionStart(); | ||
|
||
return { | ||
isNavigationModeActive: isNavigationMode(), | ||
hasSelectedBlock: | ||
!! selectionStartClientId && | ||
!! getBlock( selectionStartClientId ), | ||
}; | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<Panel | ||
header={ | ||
<Button isPrimary onClick={ saveBlocks }> | ||
{ __( 'Save navigation' ) } | ||
</Button> | ||
} | ||
> | ||
<PanelBody title={ __( 'Navigation menu' ) }> | ||
<NavigableToolbar | ||
className={ classnames( | ||
'edit-navigation-menu-editor__block-editor-toolbar', | ||
{ | ||
'is-hidden': isNavigationModeActive, | ||
} | ||
) } | ||
aria-label={ __( 'Block tools' ) } | ||
> | ||
{ hasSelectedBlock && <BlockToolbar hideDragHandle /> } | ||
</NavigableToolbar> | ||
<Popover.Slot name="block-toolbar" /> | ||
<WritingFlow> | ||
<ObserveTyping> | ||
<BlockList /> | ||
</ObserveTyping> | ||
</WritingFlow> | ||
</PanelBody> | ||
</Panel> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/edit-navigation/src/components/menu-editor/navigation-structure-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalBlockNavigationList } from '@wordpress/block-editor'; | ||
import { Panel, PanelBody } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export default function NavigationStructurePanel( { blocks, initialOpen } ) { | ||
return ( | ||
<Panel> | ||
<PanelBody | ||
title={ __( 'Navigation structure' ) } | ||
initialOpen={ initialOpen } | ||
> | ||
{ !! blocks.length && ( | ||
<__experimentalBlockNavigationList | ||
blocks={ blocks } | ||
selectedBlockClientId={ blocks[ 0 ].clientId } | ||
selectBlock={ () => {} } | ||
showNestedBlocks | ||
showAppender | ||
/> | ||
) } | ||
</PanelBody> | ||
</Panel> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wouldn't it be fine to just render the toolbar slot in a fixed position?
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.
Using the
BlockToolbar
component mirrors the way the fixed toolbar is implemented in the post editor. My thoughts were that this is preferable as the movers are implemented differently inBlockToolbar
component—they're inline buttons. Whereas with the Slot, the movers reveal and have a drag handle, which doesn't seem like the right behaviour for an inline toolbar.