Fix: Block pseudo-state styles incorrectly applied to default state#11226
Fix: Block pseudo-state styles incorrectly applied to default state#11226MaggieCabrera wants to merge 2 commits intoWordPress:trunkfrom
Conversation
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. |
|
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. |
Backport for WordPress/gutenberg#76326
Core trac ticket: https://core.trac.wordpress.org/ticket/64838
What?
When a block defines a custom feature selector in its
block.json(e.g.core/buttonuses.wp-block-buttonforwritingModerather than the root.wp-block-button .wp-block-button__link), styles set on a pseudo-state like:hovervia theme.json were being output under the default-state selector instead of the pseudo-state selector.Why?
This bug will become more apparent when there's a UI to change the state of the button block after WordPress/gutenberg#75627 lands.
How?
In get_block_nodes, the metadata node for a block pseudo-state was built with the original $feature_selectors (e.g. .wp-block-button) rather than the pseudo-scoped version (e.g. .wp-block-button:hover). The fix builds a $pseudo_feature_selectors array that appends the pseudo-selector to every feature selector string before the node is created.
We have added a test to catch this problem should there be a regression
Testing Instructions
Add writing mode to a button block on hover on theme.json, check the frontend and you will see the CSS generated:
Before:
:root :where(.wp-block-button) { writing-mode: vertical-rl; }After:
:root :where(.wp-block-button:hover) { writing-mode: vertical-rl; }The unit tests should all pass too