-
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
Added filters for menu icons and improved accessibility on svg elements (icons) #46624
base: trunk
Are you sure you want to change the base?
Conversation
I am not sure about |
After submitting PR, I came to idea that it may be good thing to provide $attributes variable to menu filters as well. User may have multiple instances of menu blocks on page and want to have different menu icons on different blocks? |
@Lovor01 Could you please look in to the failing PHP unit tests? Thanks. |
Please ignore React Native E2E Test fail, I changed only PHP. They failed because iOS screen snippets failing to create, I am not sure why, but it has nothing to do with my proposed changes. |
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.
@Lovor01 Looks good to me. Let me see if I can track down one more review. 👍
@getdave Can you review this or tag someone who can? Thanks. |
Can you please provide a complete code example as part of the testing instructions? |
@carolinan It would be something like this.
AND
Does this help? |
I have tested the PR, do I understand correctly that all it does is change the icon that is used on the front? I also don't think that it solves the need that is described in the initial issue? Since the user can not select the custom icon in the UI, it actually limits their options. |
All it does is add filters that allow you to pass in a custom SVG.
I would not say it limits options but it is not a UI solution for sure. This is an implementation suited for developers who wish to use custom code to override the outputted SVG. Those filters could be added in a mu-plugin, plugin, or child theme. Looks like https://developer.wordpress.org/reference/hooks/render_block/ I think what really needs to be answered here is should this be a UI feature or should this be adjustable for developers? If the first is true, this PR should be closed. If the second is true, I say this is a good solution. Thanks. |
Let me jump into discussion with just a quick note. There were requests for possibility to change menu icon, which is quite legitimate, some suggestions in 37930 propose filters. This is a quick fix for developers and it does not stand in a way of addition of javascript solution to give user possibility to upload images from editor. Proposed solution with filters can co-exist with javascript UI solution. |
And if you do use render_block hook to change icons, regular expressions must be used to change block content, which is not so elegant solution as filters and regular expressions are not as fast. Also, block code may change in the future, which may result in regular expressions replacements stop functioning. Filters are more future-proof solution. |
Thank you for this PR. Tagging @ajlende for his expertise with SVG. I'll also add to my review queue. |
The main point of concern around SVGs is security. Adding a filter that replaces the entire SVG like this puts the burden of security onto plugin/theme developers which, I think, is fine.
Let's say that this PR is merged as-is, a plugin/theme has used the filter, and later a solution for the UI is added to give the user control over the icon. How do you propose that the filter co-exists with the new UI? In most cases for things like this, I think the filter is usually on the list of items that the user can select from rather than the final rendered output. |
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'm not sure we want to introduce these filters as they may not be needed. I should be able to provide a PoC that will allow developers to update these icons using existing tools. I'll try and spin that up soon.
Hi, @getdave Hope you are doing well. I am currently working on the same where I required a way to add more icons for the navigation hamburger. So would love to see a filter or workaround for the same if possible. You mentioned that you will be working PoC that will allow developers to update these icons using existing tools. So if there is any update to that then please let me know. As I am highly interested in knowing the same, Thanks |
What?
Added two commits:
Why?
This addresses #37930 issue.
How?
Two filters in PHP render functions of block are added, developer can add their own icons via these filters.
Testing Instructions
Use new filters
block_core_navigation_menu_toggle_icon
andblock_core_navigation_menu_close_icon
in e.g. functions.php of the theme to return desired svg or img elements.Testing Instructions for Keyboard
Not relevant
Screenshots or screencast
Not relevant