Skip to content

Navigation: Add a shared helper for font sizes in Navigation Link and Navigation Submenu blocks#74855

Merged
scruffian merged 15 commits intotrunkfrom
update/block_core_shared_navigation_build_css_font_sizes
Mar 28, 2026
Merged

Navigation: Add a shared helper for font sizes in Navigation Link and Navigation Submenu blocks#74855
scruffian merged 15 commits intotrunkfrom
update/block_core_shared_navigation_build_css_font_sizes

Conversation

@scruffian
Copy link
Copy Markdown
Contributor

@scruffian scruffian commented Jan 22, 2026

What?

Consolidate the font size calculation function for navigation link and navigation submenu blocks to a shared helper.

Why?

Reducing duplicate code avoids bugs and makes maintenance easier.

How?

Moved the duplicate build_css_font_sizes functions from navigation-link and navigation-submenu to a new shared file: packages/block-library/src/navigation-link/shared/build-css-font-sizes.php

Testing Instructions

  1. Add a Navigation block to a post/page
  2. Add some Navigation Link and Navigation Submenu blocks within it
  3. In the block settings sidebar, set a custom font size for the navigation block
    (this applies via context to child blocks)
  4. Save and view on the frontend
  5. Verify that both navigation links and submenus display with the correct font size
  6. Test with both named font sizes (e.g., "Medium") and custom pixel values

@scruffian scruffian requested a review from getdave January 22, 2026 13:10
@scruffian scruffian self-assigned this Jan 22, 2026
@scruffian scruffian added [Type] Code Quality Issues or PRs that relate to code quality [Block] Navigation Link Affects the Navigation Link Block [Block] Submenu Affects the Submenu Block - for submenus in navigation labels Jan 22, 2026
@github-actions github-actions bot added the [Package] Block library /packages/block-library label Jan 22, 2026
@scruffian scruffian changed the title Update/block core shared navigation build css font sizes Navigation: Add a shared helper for font sizes in Navigation Link and Navigation Submenu blocks Jan 22, 2026
@scruffian
Copy link
Copy Markdown
Contributor Author

@copilot can you rebase this?

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 17, 2026

@scruffian I've opened a new pull request, #75609, to work on those changes. Once the pull request is ready, I'll request review from you.

@scruffian
Copy link
Copy Markdown
Contributor Author

@copilot can you open a new PR that consolidates the font size calculation function for navigation link and navigation submenu blocks to a shared helper?

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 18, 2026

@scruffian I've opened a new pull request, #75672, to work on those changes. Once the pull request is ready, I'll request review from you.

@scruffian scruffian force-pushed the update/block_core_shared_navigation_build_css_font_sizes branch 2 times, most recently from 042a8ea to b4f1e9b Compare February 18, 2026 17:32
…ubmenu blocks

Extract the duplicated `build_css_font_sizes` function from both
navigation-link and navigation-submenu into a shared helper file,
following the same pattern established for item-should-render and
render-submenu-icon shared helpers.

Uses the IS_GUTENBERG_PLUGIN guard at call sites so the correct
(prefixed vs unprefixed) function name is used in both the Gutenberg
plugin build and WordPress Core.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@scruffian scruffian force-pushed the update/block_core_shared_navigation_build_css_font_sizes branch from 192cb26 to 23e4ea2 Compare March 12, 2026 10:13
@scruffian scruffian marked this pull request as ready for review March 12, 2026 10:23
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 12, 2026

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: scruffian <scruffian@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>

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

Copy link
Copy Markdown
Contributor

@jeryj jeryj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both home-link and page-list blocks use the same font sizes function. Let's update those to use this shared function too. Thanks for this refactor! One function instead of four identical ones is much better!

return '';
}

$font_sizes = block_core_navigation_link_build_css_font_sizes( $block->context );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in #75685 (comment), I prefer leaving this and putting the IS_GUTENBERG_PLUGIN logic within it with comments to help explain it and hide the complexity. This line could stay the same and the complexity goes within block_core_navigation_link_build_css_font_sizes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because block_core_navigation_link_build_css_font_sizes isn't defined in core yet, so we'll get a fatal error (Uncaught Error: Call to undefined function block_core_shared_get_submenu_visibility()). That solution will only work once the function is backported to core.

scruffian and others added 5 commits March 19, 2026 14:56
Replace the duplicate block_core_page_list_build_css_font_sizes function
with the shared block_core_shared_navigation_build_css_font_sizes helper,
matching the pattern used by Navigation Link and Submenu blocks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the duplicate block_core_home_link_build_css_font_sizes function
with the shared block_core_shared_navigation_build_css_font_sizes helper.
This also fixes Home Link not supporting fluid typography for custom font
sizes, aligning it with Navigation Link, Submenu, and Page List blocks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove extra alignment spaces on $colors and $classes assignments
that were left over after replacing the single-line $font_sizes
assignment with a multi-line IS_GUTENBERG_PLUGIN conditional block.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ites

The gutenberg_ prefix is needed because Core already defines its own
per-block build_css_font_sizes functions, and the shared file cannot
redeclare them without causing a fatal error. The else branch calls the
unprefixed shared helper which will be available once backported to Core.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@scruffian
Copy link
Copy Markdown
Contributor Author

@jeryj thanks for testing. I have made the comments more explicit but I don't think we can do as you suggest above.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it works with preset and custom sizes.

Noticed some nits.

* Build an array with CSS classes and inline styles defining the font sizes
* which will be applied to the navigation markup in the front-end.
*
* @since 5.9.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need updating?

scruffian and others added 7 commits March 28, 2026 10:33
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
@scruffian scruffian enabled auto-merge (squash) March 28, 2026 01:34
@github-actions
Copy link
Copy Markdown

Flaky tests detected in c68b0d1.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23674514733
📝 Reported issues:

@scruffian scruffian disabled auto-merge March 28, 2026 02:10
@scruffian scruffian enabled auto-merge (squash) March 28, 2026 02:10
@scruffian scruffian merged commit 5f60541 into trunk Mar 28, 2026
39 checks passed
@scruffian scruffian deleted the update/block_core_shared_navigation_build_css_font_sizes branch March 28, 2026 02:15
@github-actions github-actions bot added this to the Gutenberg 22.9 milestone Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Link Affects the Navigation Link Block [Block] Submenu Affects the Submenu Block - for submenus in navigation [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants