Skip to content
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

Add create new menu button to nav block #36245

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ function Navigation( {
setNavigationMenuId( id );
onClose();
} }
onCreateNew={ () => {
if ( navigationArea ) {
setAreaMenu( 0 );
}
setAttributes( {
navigationMenuId: undefined,
} );
setIsPlaceholderShown( true );
} }
/>
) }
</ToolbarDropdownMenu>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
/**
* WordPress dependencies
*/
import { MenuGroup, MenuItemsChoice } from '@wordpress/components';
import { MenuGroup, MenuItem, MenuItemsChoice } from '@wordpress/components';
import { useEntityId } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import useNavigationMenu from '../use-navigation-menu';

export default function NavigationMenuSelector( { onSelect } ) {
export default function NavigationMenuSelector( { onSelect, onCreateNew } ) {
const { navigationMenus } = useNavigationMenu();
const navigationMenuId = useEntityId( 'postType', 'wp_navigation' );

return (
<MenuGroup>
<MenuItemsChoice
value={ navigationMenuId }
onSelect={ ( selectedId ) =>
onSelect(
navigationMenus.find(
( post ) => post.id === selectedId
<>
<MenuGroup>
<MenuItemsChoice
value={ navigationMenuId }
onSelect={ ( selectedId ) =>
onSelect(
navigationMenus.find(
( post ) => post.id === selectedId
)
)
)
}
choices={ navigationMenus.map( ( { id, title } ) => ( {
value: id,
label: title.rendered,
} ) ) }
/>
</MenuGroup>
}
choices={ navigationMenus.map( ( { id, title } ) => ( {
value: id,
label: title.rendered,
} ) ) }
/>
</MenuGroup>
<MenuGroup>
<MenuItem onClick={ onCreateNew }>
{ __( 'Create new menu' ) }
</MenuItem>
</MenuGroup>
</>
);
}