Fix: State styles – clear background-image when hover sets a solid background-color#78992
Fix: State styles – clear background-image when hover sets a solid background-color#78992i-am-chitti wants to merge 2 commits into
background-image when hover sets a solid background-color#78992Conversation
|
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. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
What?
Closes #78900
Emits
background-image: none !importantwhen a state (e.g.:hover) sets a solidbackground-colorwithout its own gradient, preventing the default-state gradient from bleeding through.Why?
When a block instance has a gradient applied to its default state and a solid background color applied to a pseudo-state like
:hover, the hover color never appears. The gradient keeps winning despite the state styles using!important.This is a CSS property mismatch: gradients render as
background(shorthand) orbackground-image, while solid colors render asbackground-color. Since!importantonly resolves ties between declarations of the same property, the gradient image layer is never cleared by the hover rule.How?
Mirrors the existing
border-stylefallback pattern already in the states support:PHP (
lib/block-supports/states.php): Addedgutenberg_get_state_declarations_with_background_resets(), called alongside the existinggutenberg_get_state_declarations_with_fallback_border_styles(). When compiled declarations includebackground-colorbut nobackgroundorbackground-image, it appendsbackground-image: none !important.JS (
packages/block-editor/src/hooks/style.js): AddedgetStateBackgroundResetCSS()helper wired intogetStateStylesCSS(). Checkscolor.gradient,background.gradient, andbackground.backgroundImageto avoid adding the reset when the state itself sets a gradient.Both the legacy
color.gradientpath (emitsbackgroundshorthand) and the modernbackground.gradientpath (emitsbackground-image) are covered.Testing Instructions
:hoverstate.#ffffff).Expected: The solid hover color replaces the gradient on hover.
Before this fix: The gradient remained visible on hover despite the solid color being set.
Testing Instructions for Keyboard
The fix is purely server-side/CSS — no interactive UI changes. Standard keyboard navigation of the editor is unaffected.
Screenshots or screencast
Before
Screen.Recording.2026-06-06.at.7.31.23.PM.mp4
After
Screen.Recording.2026-06-06.at.7.29.51.PM.mp4
Use of AI Tools
Copilot CLI was used to help identify the affected code paths, draft the implementation and generate tests. Each generated code was reviewed and verified manually.