NavigationLink: fix getting Navigation parent block #20032
Merged
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.
Description
This PR fixes an issue which was found by @getdave reviewing this PR):
...However, I noticed a potential coding issue where we're expecting the rootBlock to always be the Nav Block:
...when in actual fact I think it could actually be any parent Block that uses
InnerBlocks
(eg: Columms) as it will return the topmost Block in the hierarchy. Therefore if the Block is nested then this logic is problematic.I tested this theory by:
style
attribute set on the DOM on the Nav Link.It appears in the above scenario it doesn't work as the style wasn't applied to the Navigation Link Block, only to the parent Navigation Block.
So, in order to fix this issue what we do is adding a new
getBlockParentsByBlockName()
selector, which returns an array of parent client IDs, but also filtered by block name. So in this way, will ensure to get the proper attributes of the parent block:Then it's a matter of getting the first item of the array and pick up the block attributes.
How has this been tested?
style
attribute set on the DOM on the Nav Link.before
5) The colors attributes of the Navigation block are not propagated to the NavigationLink and the colors are not applied to the sub-menus:
after
6) The colors are righty applied to the NavigationLink blocks
Types of changes
Checklist: