-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 a Submenu block for use in Navigation #33775
Merged
Merged
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
2d1f90e
Add a Dropdown block for use in Navigation
tellthemachines 7821084
display dropdowns below buttons in editor
tellthemachines ab180c9
Add open on click functionality.
tellthemachines 7ce9bca
Adjustments to click behaviour.
tellthemachines e48c0b7
Fix submenu logic
tellthemachines 95a6f3f
Transform nav links to submenus
tellthemachines 6e6c908
Change block name to Submenu and update classnames
tellthemachines 89f33e5
Add submenu transform to navigation link.
tellthemachines 4fb0716
Remove button default styling
tellthemachines 8ed3e1d
Don't split at end.
tellthemachines fedffa3
Add block fixture.
tellthemachines 451b70f
Fix php lint errors.
tellthemachines 0cb9fe6
Update submenu icon classname.
tellthemachines 520dac7
Use Submenu in Page List conversion to blocks.
tellthemachines c1f8bac
Don't lose children when transforming to Submenu.
tellthemachines f0e00aa
Fix link conversion in Page List block.
tellthemachines 7112200
Add link to empty submenu and default navigation class.
tellthemachines 3e32cd4
Introduce hover/click toggle on Navigation.
tellthemachines beb977f
Don't add link in submenu straightaway.
tellthemachines b14c119
Open link control on parent element when hover is set.
tellthemachines 0fee1ca
Always show icons when opening on click.
tellthemachines 1e39756
Open submenus on click in the editor.
tellthemachines f1c9696
Fix button styles and change toggle label.
tellthemachines 313f757
Update navigation fixture and fix php lint errors.
tellthemachines 1764eba
Fix php lint error.
tellthemachines c6f531e
Fix php lint error.
tellthemachines 19f9901
Try hiding submenu in block inserter.
tellthemachines e8e7f04
Update menu items to blocks conversion.
tellthemachines ea847ad
Update menu items to blocks test.
tellthemachines 71bbd83
Fix navigation link top level item status.
tellthemachines 0738c48
Update and add new e2e test for open on click.
tellthemachines aec69a2
Fix undo/redo trap.
tellthemachines 04f50f7
Fix styling for nested submenus in the editor.
tellthemachines 55f7a06
Remove obsolete lint ignore
tellthemachines 2886cb7
Display block label in list view.
tellthemachines 2d30be1
Fix dropdown z-index
tellthemachines c414417
Switch toggle position
tellthemachines 530e32a
Pointer cursor on button toggles.
tellthemachines fdde85d
Fix max nesting and top level link logic.
tellthemachines 82d7ad7
Show in inserter.
tellthemachines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -292,7 +292,7 @@ export default function NavigationLinkEdit( { | |
const { showSubmenuIcon } = context; | ||
const { saveEntityRecord } = useDispatch( coreStore ); | ||
const { | ||
insertBlock, | ||
replaceBlock, | ||
__unstableMarkNextChangeAsNotPersistent, | ||
} = useDispatch( blockEditorStore ); | ||
const [ isLinkOpen, setIsLinkOpen ] = useState( false ); | ||
|
@@ -302,18 +302,19 @@ export default function NavigationLinkEdit( { | |
const ref = useRef(); | ||
|
||
const { | ||
innerBlocks, | ||
isAtMaxNesting, | ||
isTopLevelLink, | ||
isParentOfSelectedBlock, | ||
isImmediateParentOfSelectedBlock, | ||
hasDescendants, | ||
selectedBlockHasDescendants, | ||
numberOfDescendants, | ||
userCanCreatePages, | ||
userCanCreatePosts, | ||
} = useSelect( | ||
( select ) => { | ||
const { | ||
getBlocks, | ||
getClientIdsOfDescendants, | ||
hasSelectedInnerBlock, | ||
getSelectedBlockClientId, | ||
|
@@ -326,11 +327,16 @@ export default function NavigationLinkEdit( { | |
.length; | ||
|
||
return { | ||
innerBlocks: getBlocks( clientId ), | ||
isAtMaxNesting: | ||
getBlockParentsByBlockName( clientId, name ).length >= | ||
MAX_NESTING, | ||
// Temporary fix until navigation link submenus are properly deprecated. | ||
isTopLevelLink: | ||
getBlockParentsByBlockName( clientId, name ).length === 0, | ||
getBlockParentsByBlockName( clientId, [ | ||
name, | ||
'core/navigation-submenu', | ||
] ).length === 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know that it's possible to deprecate from one block type to another. 🤔 It might also be more flexible to make this check if the parent is a |
||
isParentOfSelectedBlock: hasSelectedInnerBlock( | ||
clientId, | ||
true | ||
|
@@ -343,7 +349,6 @@ export default function NavigationLinkEdit( { | |
selectedBlockHasDescendants: !! getClientIdsOfDescendants( [ | ||
selectedBlockId, | ||
] )?.length, | ||
numberOfDescendants: descendants, | ||
userCanCreatePages: select( coreStore ).canUser( | ||
'create', | ||
'pages' | ||
|
@@ -367,12 +372,15 @@ export default function NavigationLinkEdit( { | |
}, [ isTopLevelLink ] ); | ||
|
||
/** | ||
* Insert a link block when submenu is added. | ||
* Transform to submenu block. | ||
*/ | ||
function insertLinkBlock() { | ||
const insertionPoint = numberOfDescendants; | ||
const blockToInsert = createBlock( 'core/navigation-link' ); | ||
insertBlock( blockToInsert, insertionPoint, clientId ); | ||
function transformToSubmenu() { | ||
const newSubmenu = createBlock( | ||
'core/navigation-submenu', | ||
attributes, | ||
innerBlocks | ||
); | ||
replaceBlock( clientId, newSubmenu ); | ||
} | ||
|
||
// Show the LinkControl on mount if the URL is empty | ||
|
@@ -596,7 +604,7 @@ export default function NavigationLinkEdit( { | |
name="submenu" | ||
icon={ addSubmenu } | ||
title={ __( 'Add submenu' ) } | ||
onClick={ insertLinkBlock } | ||
onClick={ transformToSubmenu } | ||
/> | ||
) } | ||
</ToolbarGroup> | ||
|
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
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,67 @@ | ||
{ | ||
"apiVersion": 2, | ||
"name": "core/navigation-submenu", | ||
"title": "Submenu", | ||
"category": "design", | ||
"parent": [ | ||
"core/navigation" | ||
], | ||
"description": "Add a submenu to your navigation.", | ||
"textdomain": "default", | ||
"attributes": { | ||
"label": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"rel": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "number" | ||
}, | ||
"opensInNewTab": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"url": { | ||
"type": "string" | ||
}, | ||
"title": { | ||
"type": "string" | ||
}, | ||
"kind": { | ||
"type": "string" | ||
}, | ||
"isTopLevelItem": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"usesContext": [ | ||
"textColor", | ||
"customTextColor", | ||
"backgroundColor", | ||
"customBackgroundColor", | ||
"overlayTextColor", | ||
"customOverlayTextColor", | ||
"overlayBackgroundColor", | ||
"customOverlayBackgroundColor", | ||
"fontSize", | ||
"customFontSize", | ||
"showSubmenuIcon", | ||
"openSubmenusOnClick", | ||
"style" | ||
], | ||
"supports": { | ||
"reusable": false, | ||
"html": false, | ||
"inserter": false | ||
}, | ||
"viewScript": "file:./view.min.js", | ||
"editorStyle": "wp-block-navigation-submenu-editor", | ||
"style": "wp-block-navigation-submenu" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
name
be expanded to take into account the submenu block the same wayisTopLevelLink
does?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thanks, totally missed that 😅