-
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
Fix broken list markup in navigation block when 3rd party blocks are used as decendants of navigation block #55551
Fix broken list markup in navigation block when 3rd party blocks are used as decendants of navigation block #55551
Conversation
Flaky tests detected in 2ceb918. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7817679815
|
8b68bec
to
216bfd0
Compare
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.
Not had time to look into this in detail yet but if htis relates to handling li
tags then do we need to amend $needs_list_item_wrapper
as well?
Also does this open the block up to theoretically containing all types of blocks?
That is a very good question... I'm not sure how we can make that distinction. Regardless currently the logic is implemented in the incorrect order. We should first wrap the blocks in an LI and then check whether they have an Currently the code I have here produces the markup where the site logo is wrapped in an So that will need to be fixed before this can be merged... Looking at the current setup the because of that I would for now leave that manual hardcoded list in place |
Just added a new commit that takes care of excluding those blocks that manually get wrapped in the |
@scruffian In light of your refactor in #55605 this is relevant. @fabiankaegy you might like to also take a look at this. |
Hi Fabian, thanks for trying to improve this block 🙏 and it's giant pile of past decisions 😀 Although the idea of the PR is interesting (it's nice to rely on the power of the tag processor) - I have doubts about the "why" of the PR: it seems unlikely the navigation block will become "open" to other blocks at this stage. Random blocks would become able to join a navigation either via the new block hooks API or when the block will offer "mega menu" creation abilities. For now that markup is too easy to break IMO if any block can be inserted. What do you think? |
@draganescu I do share your concerns about the complexity here and how fragile the navigation block seems. But I have to disagree that we should not open it up for extenders to insert other type of elements within. Is the solution really that extenders should instead build an entire custom navigation block from scratch when they have different more complex requirements. Core will never and should never cover all edgecases for how menus work. For example looking at techctunch.com the flyout type navigation is not something I would ever say core should handle on top of megamenus and regular submenus. But that is where extending the navigation block with other child blocks becomes really really useful and powerful. And it is already possible for anyone to add additional blocks to be used within the navigation block. The issue is just that the markup created by it becomes inaccessible because of the different lists that it creates. This would be a non-issue if the actual markup of the child blocks were checked instead of a hardcoded list of blocks that should get special treatment. I get the sentiment that opening something up for extenders means we now have a greater responsibility for backward compatibility and therefore cannot iterate easily anymore. But especially on navigations which are the primary way of navigating through a site that every user will have to interact with, the ability to customize the experience more by allowing other blocks to be used within (which already is possible) is really important from my point of view. |
I think we're both on the same page, I just don't understand what doesn't for instance the new block hooks option offer? Also what other blocks have extendable allowed innerBlocks? The current block API is so that when a block has innerblocks and it defines what kinds of blocks are allowed it is not something that can be changed. Blocks have all kinds of limitations in terms of what they allow and what they disallow and currently the way to extend this is via what may be interpreted as a leaky API via filtering the render. I do not disagree with you at all that the navigation block is important and that it will never cover on its own all the cases and that it should be extendable. I only want to make sure that the way in which this extendability works is not something that limits its future development. |
245c57d
to
1c598d8
Compare
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/blocks/class-wp-navigation-block-renderer-test.php |
c96bf0e
to
7bcfc62
Compare
@fabiankaegy If we progress this we should probably add additional test cases to https://github.com/WordPress/gutenberg/blob/trunk/phpunit/class-wp-navigation-block-renderer-test.php to check that blocks that are not in the original constant (the one this PR no longer relies upon) are "wrapped" correctly. |
7bcfc62
to
53f452a
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I just rebased this PR and resolved any conflicts 👍 |
Hey all 👋 I wanted to re surface this discussion here in light of the recent merge of #58262 which makes it much easier to manipulate the list of inner blocks used within the navigation. But as it stands today this will create a large accessibility issue because of the hardcoded list for which blocks get the special treatment. I'd love to get some additional input on the approach here and see if we could land this alongside #58262 in WordPress 6.5 CC: @getdave @youknowriad |
Using the new method of filtering However, the front-end markup looks like this, which is not that great. Placing the icon in the middle of the navigation breaks the links into two separate lists. Would this PR fix that @fabiankaegy? Note that I am getting a static error when testing this PR:
|
@ndiego yes exactly that is the aim of this PR. That is the reason it exists. Tough it looks like my lates rebase created an issue. So I will take a look at that. Thanks for testing! |
3dd0287
to
222ef57
Compare
Just want to check the JavaScript Unit test failures here. |
Thank you all for your help landing this ❤️ |
Dev note - Introducing the
|
@getdave Thank you for adding this ❤️. It was on my todo list for today :) What you have writen is clear and correct 👍 I am happy with this being the dev note for the feature |
Oh sorry I hope I didn't step on your toes! 🤦 I had some notes written up from when I investigated the issue and felt it should be added as the dev note. Glad it works for you. |
Ohh no, no worries :) I'm glad you added this :) |
Was this included in 6.5? I am testing the code snippet above and I am struggling to get it to work. |
This comment was marked as resolved.
This comment was marked as resolved.
Ok panic over - it was included in the final Gutenberg release 17.7.0RC. So that means it should be in Core. |
@ndiego I think I made a typo in the docs. The filter is:
As per this line. I've updated the docs and will ping the relevant release leads to get the docs updated. cc @fabiankaegy for confidence check. |
Ah, that's it! I just copied the code snippet. All is working. Thanks! |
What?
Use the HTML_Tag_Processor to check if an inner block markup is wrapped in a
li
element instead of using an hardcoded list of allowed inner blocks.Why?
The hard-coded list of blocks that it should be applied to prevented custom blocks from getting the handling which led to inaccessible markup.
How?
Using the
HTML_Tag_Processor
to check if the wrapper element is anli
elementTesting Instructions
Testing Instructions for Keyboard
Screenshots or screencast