Backport: Navigation link: add support to style current menu item via theme.json#11174
Backport: Navigation link: add support to style current menu item via theme.json#11174MaggieCabrera wants to merge 6 commits into
Conversation
8ef2465 to
5ff8b02
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
b393ff3 to
534fdaa
Compare
tellthemachines
left a comment
There was a problem hiding this comment.
Aside from the submenu addition which I don't believe we should add here without adding first in Gutenberg, the rest of the changeset looks consistent with #75736.
The PHP unit tests are failing because they're testing get_stylesheet, which relies on data from the actual block attributes, and we won't get that in core until gutenberg is synced.
A good alternative would be to test get_styles_for_block instead and pass it the style nodes, so it's independent of the gutenberg sync and I think makes sense for this changeset because it's closer to where the changes actually are (we haven't changed get_stylesheet so we shouldn't have to test it). You can check the tests in #11706 for a similar approach.
40909ba to
9ee02ee
Compare
|
I updated this PR with the changes discussed plus rebased it and made it sure it was up to date with what is in Gutenberg right now. It should be ready for review |
tellthemachines
left a comment
There was a problem hiding this comment.
The changes won't be testable in the core dev env until the editor files are updated to include the change from WordPress/gutenberg#79210.
The code mostly looks good, just a couple things I commented on below!
| 'selectors' => $feature_selectors, | ||
| 'duotone' => $duotone_selector, | ||
| 'variations' => $variation_selectors, | ||
| 'css' => $custom_css_selector, |
There was a problem hiding this comment.
Comparing with gutenberg we're missing 'elements' => $selectors[ $name ]['elements'] ?? array(), in this array as well as in the one from the loop below (those were added as part of WordPress/gutenberg#77513)
What?
This backports the relevant changes from WordPress/gutenberg#75736, updated to match the current Gutenberg trunk state after:
@currentto-current.Why?
Theme authors need a way to style the active/current menu item differently from the rest of the navigation, including controlling its hover, focus, and active states.
How?
No UI changes are included; this is theme.json only.
A new
VALID_BLOCK_CUSTOM_STATESconstant whitelists--prefixed states per block in theme.json, playing the same role thatVALID_BLOCK_PSEUDO_SELECTORSplays for CSS pseudo-selectors. The-prefix distinguishes these class-based custom states from real CSS pseudo-selectors and responsive breakpoint states.Each block declares its state CSS selectors in
block.jsonunderselectors.states, following the existing Selectors API pattern, whichget_blocks_metadata()reads into block metadata andget_block_nodes()uses to generate CSS.Blocks listed in
VALID_BLOCK_CUSTOM_STATESalso inherit theirVALID_BLOCK_PSEUDO_SELECTORSas valid sub-states, producing compound selectors like.wp-block-navigation-item.current-menu-item:hover.The PHPUnit tests use
get_styles_for_block()with explicit style nodes so they do not depend on block metadata that will arrive through the Gutenberg sync.We've had initial discussions on how the UI for this scenario would look like over here.
Testing Instructions
Run the relevant PHP unit tests for
WP_Theme_JSON, especially the custom-state tests added in this PR.The following theme.json snippets show the intended public API once the corresponding
selectors.statesmetadata forcore/navigation-linkis available in Core through the Gutenberg sync.Current item base styles:
Current item hover:
Current item focus:
All combined:
Test for navigation link items with and without submenus. Try other styles that aren't just the text color.
Testing Instructions for Keyboard
Screenshots or screencast
Trac ticket:
https://core.trac.wordpress.org/ticket/64806