Skip to content

Commit

Permalink
Fix: Inserter on navigation menu sidebar.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Feb 13, 2023
1 parent 55a71ae commit a433b4f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/edit-site/src/components/navigation-inspector/appender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* WordPress dependencies
*/
import { Inserter } from '@wordpress/block-editor';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { plus } from '@wordpress/icons';

export default function Appender( { clientId } ) {
return (
<div className="edit-site-navigation-inspector__appender">
<Inserter
rootClientId={ clientId }
position="bottom right"
isAppender={ true }
selectBlockOnInsert={ false }
shouldDirectInsert={ false }
__experimentalIsQuick
renderToggle={ ( {
onToggle,
disabled,
isOpen,
hasSingleBlockType,
toggleProps = {},
} ) => {
const { onClick, ...rest } = toggleProps;
// Handle both onClick functions from the toggle and the parent component.
function handleClick( event ) {
if ( onToggle ) {
onToggle( event );
}
if ( onClick ) {
onClick( event );
}
}
return (
<Button
icon={ plus }
onClick={ handleClick }
className="block-editor-inserter__toggle"
aria-haspopup={
! hasSingleBlockType ? 'true' : false
}
aria-expanded={
! hasSingleBlockType ? isOpen : false
}
disabled={ disabled }
{ ...rest }
>
{ __( 'Add menu item' ) }
</Button>
);
} }
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useSelect } from '@wordpress/data';
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import Appender from './appender';

/**
* Experimental dependencies
Expand All @@ -35,6 +36,7 @@ export default function NavigationMenu( { onSelect, navigationBlockId } ) {
onSelect={ onSelect }
LeafMoreMenu={ LeafMoreMenu }
/>
<Appender clientId={ navigationBlockId } />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
.edit-site-navigation-inspector__select-menu {
margin-bottom: $grid-unit-10;
}

.offcanvas-editor-appender {
display: none;
}
}

.edit-site-navigation-inspector__placeholder {
Expand All @@ -44,3 +48,7 @@
.edit-site-navigation-inspector__empty-msg {
padding: 0 $grid-unit-10;
}

.edit-site-navigation-inspector__appender {
margin-left: $grid-unit-10;
}

0 comments on commit a433b4f

Please sign in to comment.