-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear block selection when changing menus
- Loading branch information
Showing
4 changed files
with
80 additions
and
43 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch } 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 } from '@wordpress/components'; | ||
|
||
export default function BlockEditorPanel( { menuId, saveBlocks } ) { | ||
const { clearSelectedBlock } = useDispatch( 'core/block-editor' ); | ||
|
||
// 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="edit-navigation-menu-editor__block-editor-toolbar" | ||
aria-label={ __( 'Block tools' ) } | ||
> | ||
<BlockToolbar hideDragHandle /> | ||
</NavigableToolbar> | ||
<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
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalBlockNavigationList } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Panel, PanelBody } from '@wordpress/components'; | ||
|
||
export default function NavigationStructurePanel( { blocks } ) { | ||
return ( | ||
<Panel> | ||
<PanelBody title={ __( 'Navigation structure' ) }> | ||
{ !! 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