Apply block styles to Page List items when nested in a Submenu - #80841
Apply block styles to Page List items when nested in a Submenu#80841sarthaknagoshe2002 wants to merge 1 commit into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
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. |
What?
Closes #80000
This PR ensures that custom styles (like text color, background color, font size, etc.) applied to a Page List block are rendered on the frontend when the block is nested inside a Navigation Submenu.
Why?
When a Page List is placed inside a Submenu, its outer
<ul>wrapper is intentionally omitted to prevent invalid HTML nesting (<ul>inside<ul>). However, becauseget_block_wrapper_attributes()was tied to that wrapper, all block support classes and inline styles were being silently discarded on the frontend, resulting in a mismatch between the editor (where styles worked) and the published site (where they disappeared).How?
This fix intercepts the generated wrapper attributes when the block is nested. It extracts the
classandstyleattributes from the discarded wrapper and manually injects them into the top-level<li>elements ($depth === 0) generated byblock_core_page_list_render_nested_page_list().Note on theme spacing: Themes that add intentional spacing between submenu items (like Twenty Twenty-Five's
margin-bottom: 3pxfor keyboard focus outline clearance) will show a thin unstyled gap between colored Page List items. This PR intentionally leaves that gap alone rather than injecting a hardcoded CSS height/margin hack, preserving the theme's box-model and accessibility choices.This can be fixed specifically for Twenty Twenty-Five theme using:
Testing Instructions
Screenshots or screencast