-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation Block: Add missing menu item attributes to core/navigation #35634
Merged
talldan
merged 11 commits into
WordPress:trunk
from
mikachan:fix/navigation-menu-item-attrs
Nov 2, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
08a0601
Navigation Block: add target, rel & title attributes
mikachan dae69cf
Nav block: change title to attr_title
mikachan 00ec38e
Nav block: add classes attribute
mikachan d006b41
Nav block: add menu item ID
mikachan ce01a7f
Merge branch 'trunk' into fix/navigation-menu-item-attrs
mikachan 691c15a
Nav block: replace className with classes
mikachan e0d8ae5
Nav block: add description, kind & type attributes
mikachan 10181ce
Nav block: improve id attribute
mikachan 376f071
Nav block: remove array to string conversion from navigation-link
mikachan 198297d
Nav block: change classes to className
mikachan 095c880
Merge branch 'trunk' into fix/navigation-menu-item-attrs
mikachan 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
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.
@mikachan Just double-checking, should this have been removed?
I was thinking that the
navigation-link/index.php
would be able to remain unchanged fromtrunk
.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.
I was seeing some of the class names being duplicated, which is why I removed this. I can't see where they're being added originally though.
With
$attributes['className']
:Without
$attributes['className']
:faq-class
(a custom test class I've added from Appearance > Menus),menu-item
,menu-item-type-post_type
, andmenu-item-object-page
are all duplicated when$attributes['className']
is used here. If I change the attribute name to something else (in bothnavigation-link/index.php
andnavigation/index.php
), then the class names are only included once, so I'm assuming something else is picking up onclassName
and adding them. If I var_dump$attributes['className']
, it only includes unique classes, and I'm struggling to find where the others are added.Ideally, I'd like to leave
navigation-link/index.php
unchanged and fix the duplication problem. If you have time, it would be great if you have any ideas around this!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.
Ah, yep, you're right, good catch. It seems like a bug in trunk that a custom class name is applied twice (happens when using the navigation block normally in the block editor too), so this would be a fix.
I think it must be via the
get_block_wrapper_attributes
function, which is defined in WordPress core:https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp-block-supports.php#L179
Since the block supports both generated and custom class names, those values get merged in like this:
https://github.com/WordPress/wordpress-develop/blob/b45c85a405ab0b1968380a79f7a76dc9293adc0f/src/wp-includes/block-supports/custom-classname.php#L44-L56
In that case it looks good to me, will approve the PR
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.
Ahh brilliant, I understand, thanks so much for explaining. Nice, unexpected bug fix!
Thanks for your help with this! 🎉