Add supports for states on single block instances#76491
Add supports for states on single block instances#76491MaggieCabrera wants to merge 27 commits intotrunkfrom
Conversation
|
Size Change: +1.22 kB (+0.02%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 7112b47. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24195717022
|
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @onetrev, @davewhitley, @itsdavidmorgan, @le-sgs. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
|
BlockStyleControls renders the same 5 panels twice — once for default state, once for non-default. Since every panel already defaults selectedState to 'default', you can always pass it and render once: |
|
Every panel (color, border, typography, dimensions, background) has near-identical boilerplate: check selectedState, read from style[selectedState], create a state-scoped onChange, wrap the resetAllFilter. Can we extract a shared hook? |
|
Can the “Show state on canvas” toggle live inside the state dropdown rather than requiring its own SlotFill? |
|
Since |
d4e46a5 to
7639d4c
Compare
I think that's not the place for it (we will have other types of states such as current, breakpoints, etc, living in the dropdown), but I agree we probably could avoid the SlotFill |
In the end I did this but I couldn't get rid of the SlotFill entirely. I don't think the toggle should be inside the dropdown, and we can't have it in the inspector controls anywhere without another SlotFill. |
Replace the $found flag and double WP_HTML_Tag_Processor instantiation with a single processor using if/elseif branching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7db4036 to
805f70e
Compare
What?
Closes #38277
Follow up of #75627
Adds block-level pseudo-state style support — allows blocks to store per-state styles (e.g. :hover, :focus, :visited) in attributes.style[':hover'] and have them serialized into the block's rendered HTML.
Why?
Right now, hover/focus/active styles for blocks like Button can only be set in Global Styles. There's no way to give a single Button block its own hover color without changing every button on the site. This adds that ability.
How?
Blocks can opt in by declaring
"states": [":hover", ":focus", ":active"]in theirblock.jsonsupports. The Button block is the first to use this. This new API adds support for a UI to a feature we already had access to through theme.json, hence why I chose not to put it under an experimental flag.In the editor:
On the frontend (PHP):
.wp-states-IDclass for this on the selector defined in block.jsonNot in this PR:
useStylein Global Styles to accept a state param — that's a follow-up, on top of the work done in Implement state UI for pseudo selectors on Global styles #75627.Testing Instructions
Screenshots or screencast
Use of AI Tools
This PR was authored with Claude Code (Claude Opus 4.6).