Skip to content

Apply block styles to Page List items when nested in a Submenu - #80841

Open
sarthaknagoshe2002 wants to merge 1 commit into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-80000
Open

Apply block styles to Page List items when nested in a Submenu#80841
sarthaknagoshe2002 wants to merge 1 commit into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-80000

Conversation

@sarthaknagoshe2002

@sarthaknagoshe2002 sarthaknagoshe2002 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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, because get_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 class and style attributes from the discarded wrapper and manually injects them into the top-level <li> elements ($depth === 0) generated by block_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: 3px for 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:

.wp-block-navigation {
    .wp-block-navigation-submenu .wp-block-navigation-item.wp-block-page-list:not(:last-child) {
		position: relative;

		&::after {
			content: "";
			position: absolute;
			inset-inline: 0;
			inset-block-end: -3px;
			block-size: 3px;
			background-color: inherit;
			pointer-events: none;
		}
	}
}

Testing Instructions

  1. Go to Appearance → Editor or create a new Post/Page.
  2. Insert a Navigation block.
  3. Add a Submenu block inside the Navigation block.
  4. Insert a Page List block inside the Submenu. (Ensure you have a few published pages on your site so they populate).
  5. Select the nested Page List block and use the Styles sidebar to apply a custom Text color and Background color.
  6. Confirm the styles apply correctly in the Editor.
  7. Save and view the site on the frontend.
  8. Open the submenu and verify that the text and background colors are now correctly applied to the Page List items.

Screenshots or screencast

Before After
image image

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jul 29, 2026
@akasunil akasunil added the [Block] Submenu Affects the Submenu Block - for submenus in navigation label Jul 29, 2026
@github-actions

Copy link
Copy Markdown

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.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block library, [Block] Submenu.

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.

@sarthaknagoshe2002
sarthaknagoshe2002 marked this pull request as ready for review July 29, 2026 18:04
@github-actions

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sarthaknagoshe2002 <sarthaknagoshe2002@git.wordpress.org>
Co-authored-by: prachigarg19 <prachigarg19@git.wordpress.org>
Co-authored-by: saulirajala <saulirajala@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Submenu Affects the Submenu Block - for submenus in navigation [Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page List: block styles are not applied on the front end when nested inside a Submenu

2 participants