Fix: Block pseudo-state styles incorrectly applied to default state#76326
Fix: Block pseudo-state styles incorrectly applied to default state#76326MaggieCabrera merged 6 commits intotrunkfrom
Conversation
|
Flaky tests detected in e499c7e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22949653068
|
|
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. |
Co-authored-by: Sarah Norris <[email protected]>
mikachan
left a comment
There was a problem hiding this comment.
Thanks for the updates! This LGTM 👍
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 #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