-
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
Changes from 6 commits
6fe780f
ae996a8
a410a8b
a45945c
16cf957
d8be3a9
a796f3c
aff58f7
a56ef6e
File filter
Filter by extension
Conversations
Jump to
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
import { | ||
BlockList, | ||
BlockToolbar, | ||
NavigableToolbar, | ||
ObserveTyping, | ||
WritingFlow, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button, Panel, PanelBody, Popover } from '@wordpress/components'; | ||
|
||
export default function BlockEditorPanel( { menuId, saveBlocks } ) { | ||
const { clearSelectedBlock } = useDispatch( 'core/block-editor' ); | ||
const isNavigationModeActive = useSelect( | ||
( select ) => select( 'core/block-editor' ).isNavigationMode(), | ||
[] | ||
); | ||
|
||
// Clear the selected block when the menu is changed. | ||
// Block selection isn't cleared implicity by the block-editor store. | ||
// Dispatching this action fixes an issue where the toolbar | ||
// for a block continues to be displayed after it no longer exists. | ||
useEffect( () => { | ||
clearSelectedBlock(); | ||
}, [ menuId ] ); | ||
|
||
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' ) } | ||
> | ||
<BlockToolbar hideDragHandle /> | ||
</NavigableToolbar> | ||
<Popover.Slot name="block-toolbar" /> | ||
<WritingFlow> | ||
<ObserveTyping> | ||
<BlockList /> | ||
</ObserveTyping> | ||
</WritingFlow> | ||
</PanelBody> | ||
</Panel> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalBlockNavigationList } from '@wordpress/block-editor'; | ||
import { Panel, PanelBody } from '@wordpress/components'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export default function NavigationStructurePanel( { blocks } ) { | ||
const isLargeViewport = useViewportMatch( 'medium' ); | ||
|
||
return ( | ||
<Panel> | ||
<PanelBody | ||
title={ __( 'Navigation structure' ) } | ||
initialOpen={ isLargeViewport } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what's wrong, but this is no longer applying? The panel is always closed, whatever the screen size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, yeah, unusual. Not sure why this happens. I moved the |
||
> | ||
{ !! blocks.length && ( | ||
<__experimentalBlockNavigationList | ||
blocks={ blocks } | ||
selectedBlockClientId={ blocks[ 0 ].clientId } | ||
selectBlock={ () => {} } | ||
showNestedBlocks | ||
showAppender | ||
/> | ||
) } | ||
</PanelBody> | ||
</Panel> | ||
); | ||
} |
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.