Make WordPress Core

Opened 6 months ago

Closed 5 months ago

#65239 closed enhancement (fixed)

Add support for style states on block instances

Reported by: isabel_brison Owned by: isabel_brison
Priority: normal Milestone: 7.1
Component: Editor Version:
Severity: normal Keywords: gutenberg-merge has-patch has-unit-tests
Cc: Focuses:

Description

​https://github.com/WordPress/gutenberg/pull/76491 adds a new "states" block support, intended to allow styling pseudo states, custom block states such as "current menu item" and specific viewport sizes. This needs adding to core.

Change History (11)

This ticket was mentioned in ​PR #11828 on ​WordPress/wordpress-develop by ​@isabel_brison.


6 months ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/65239

## Use of AI Tools

#2 @audrasjb
6 months ago

Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.

#3 @desrosj
6 months ago

  • Version trunk

Since this is an enhancement, there's no first version of WordPress this can be reproduced in. Removing trunk version.

​@isabel_brison commented on ​PR #11828:


5 months ago
#4

@andrewserong regarding the missing tests, I did omit some that were expecting button width migration changes to already be in place. Those should be added in #12046, so once that one is committed we can add a few more tests if needed.

​@andrewserong commented on ​PR #11828:


5 months ago
#5

Ah, perfect. Thanks for clarifying!

#6 @isabel_brison
5 months ago

  • Owner set to isabel_brison
  • Resolution → fixed
  • Status new → closed

In 62453:

Editor: add support for style states on block instances.

Adds a "states" block support that allows styling pseudo states and viewport sizes.

Props isabel_brison, andrewserong, ramonopoly, audrasjb, desrosj.
Fixes #65239.

​@aaronrobertshaw commented on ​PR #11828:


5 months ago
#7

Just a quick note that this will mean the ​background gradient vs color bug introduced in ​https://github.com/WordPress/gutenberg/pull/76491 will still need a follow-up in core too.

#8 @isabel_brison
5 months ago

  • Resolution fixed
  • Status closed → reopened

Reopening to add a related bug fix (see ​https://github.com/WordPress/gutenberg/pull/78992)

This ticket was mentioned in ​PR #12182 on ​WordPress/wordpress-develop by ​@iamchitti.


5 months ago
#10

  • Keywords has-unit-tests added

Backport of WordPress/gutenberg#78992.

## Description


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 showing despite the state styles using !important.


This is a CSS property mismatch: gradients render as background (shorthand) or background-image, while solid colors render as background-color. Since !important only resolves ties between declarations of the *same* property, the gradient image layer is never cleared by the hover rule.

## Changes


Added wp_get_state_declarations_with_background_resets() in src/wp-includes/block-supports/states.php, called alongside the existing wp_get_state_declarations_with_fallback_border_styles().

When compiled state declarations include background-color but no background or background-image of their own, it appends background-image: unset !important to clear any gradient from the default state.

This mirrors the existing border-style fallback pattern already in the states support, and covers both:

  • Legacy color.gradient path (emits background shorthand)
  • Modern background.gradient path (emits background-image)

Trac ticket: https://core.trac.wordpress.org/ticket/65239

## Use of AI Tools

No use of AI.

#11 @isabel_brison
5 months ago

  • Resolution → fixed
  • Status reopened → closed

In 62506:

Editor: fix background color and image incompatibility in state styles.

Unsets any existing background-image if background color is applied as a viewport state.

Props iamchitti, isabel_brison.
Fixes #65239.

Note: See TracTickets for help on using tickets.