Skip to content

Commit

Permalink
This will allow for greater customization of the navigation block, al…
Browse files Browse the repository at this point in the history
…lowing site owners to establish the default core/navigation-link variant they'd like.
  • Loading branch information
sethrubenstein committed May 27, 2023
1 parent 6a16313 commit a3b3970
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
},
"defaultBlock": {
"type": "object",
"default": {
"name": "core/navigation-link",
"attributes": {}
}
}
},
"providesContext": {
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function Navigation( {
overlayMenu,
showSubmenuIcon,
templateLock,
defaultBlock,
layout: {
justifyContent,
orientation = 'horizontal',
Expand Down Expand Up @@ -822,6 +823,7 @@ function Navigation( {
}
templateLock={ templateLock }
orientation={ orientation }
defaultBlock={ defaultBlock }
/>
) }
</ResponsiveWrapper>
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/navigation/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function NavigationInnerBlocks( {
hasCustomPlaceholder,
orientation,
templateLock,
defaultBlock,
} ) {
const {
isImmediateParentOfSelectedBlock,
Expand Down Expand Up @@ -88,6 +89,11 @@ export default function NavigationInnerBlocks( {
const showPlaceholder =
! hasCustomPlaceholder && ! hasMenuItems && ! isSelected;

// If the `defaultBlock` attribute is set and itself has an attributes object with values then use it
// otherwise fallback to the DEFAULT_BLOCK constant.
// This allows site owners to set the default `core/navigation-link` variation to use.
const navDefaultBlock = defaultBlock && defaultBlock.attributes && Object.keys(defaultBlock.attributes).length > 0 ? defaultBlock : DEFAULT_BLOCK;

const innerBlocksProps = useInnerBlocksProps(
{
className: 'wp-block-navigation__container',
Expand All @@ -98,7 +104,7 @@ export default function NavigationInnerBlocks( {
onChange,
allowedBlocks: ALLOWED_BLOCKS,
prioritizedInserterBlocks: PRIORITIZED_INSERTER_BLOCKS,
__experimentalDefaultBlock: DEFAULT_BLOCK,
__experimentalDefaultBlock: navDefaultBlock,
__experimentalDirectInsert: shouldDirectInsert,
orientation,
templateLock,
Expand Down

0 comments on commit a3b3970

Please sign in to comment.