Skip to content

Commit

Permalink
makes maxNestingLevel available via context set by the navigation block
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Draganescu committed Mar 6, 2022
1 parent 5a1eaf6 commit a7b9e41
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht
- **Name:** core/navigation
- **Category:** theme
- **Supports:** align (full, wide), anchor, inserter, spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, textColor
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, textColor

## Navigation Area

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"fontSize",
"customFontSize",
"showSubmenuIcon",
"maxNestingLevel",
"style"
],
"supports": {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ export default function NavigationLinkEdit( {
onReplace,
context,
clientId,
maxNestingLevel = 5,
} ) {
const {
label,
Expand All @@ -338,6 +337,8 @@ export default function NavigationLinkEdit( {
kind,
} = attributes;

const { maxNestingLevel } = context;

const link = {
url,
opensInNewTab,
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-submenu/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"fontSize",
"customFontSize",
"showSubmenuIcon",
"maxNestingLevel",
"openSubmenusOnClick",
"style"
],
Expand Down
6 changes: 2 additions & 4 deletions packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ const DEFAULT_BLOCK = {
name: 'core/navigation-link',
};

const MAX_NESTING = 5;

/**
* A React hook to determine if it's dragging within the target element.
*
Expand Down Expand Up @@ -293,7 +291,7 @@ export default function NavigationSubmenuEdit( {
url,
opensInNewTab,
};
const { showSubmenuIcon, openSubmenusOnClick } = context;
const { showSubmenuIcon, maxNestingLevel, openSubmenusOnClick } = context;
const { saveEntityRecord } = useDispatch( coreStore );

const {
Expand Down Expand Up @@ -351,7 +349,7 @@ export default function NavigationSubmenuEdit( {
return {
isAtMaxNesting:
getBlockParentsByBlockName( clientId, name ).length >=
MAX_NESTING,
maxNestingLevel,
isTopLevelItem:
getBlockParentsByBlockName( clientId, name ).length === 0,
isParentOfSelectedBlock: hasSelectedInnerBlock(
Expand Down
7 changes: 6 additions & 1 deletion packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
},
"customOverlayTextColor": {
"type": "string"
},
"maxNestingLevel": {
"type": "number",
"default": 3
}
},
"usesContext": [ "navigationArea" ],
Expand All @@ -76,7 +80,8 @@
"showSubmenuIcon": "showSubmenuIcon",
"openSubmenusOnClick": "openSubmenusOnClick",
"style": "style",
"orientation": "orientation"
"orientation": "orientation",
"maxNestingLevel": "maxNestingLevel"
},
"supports": {
"align": [ "wide", "full" ],
Expand Down

0 comments on commit a7b9e41

Please sign in to comment.