Skip to content

Commit 7d8bfa1

Browse files
Block Supports: Read the block's resting styles for the variation text clip base.
A block pseudo node, such as `:hover`, lists the block's style variations too. The variation rule it re-emits used the pseudo styles as its text clip base, so a clip set only in `:hover` added escapes to the variation's resting rule. Read the block's own styles instead. Drops the instance box clip test, which the text clip helper tests already cover, and adds a `WP_Theme_JSON` regression test for the pseudo node case. Synced from WordPress/gutenberg#86164.
1 parent 89eaef5 commit 7d8bfa1

3 files changed

Lines changed: 60 additions & 39 deletions

File tree

‎src/wp-includes/class-wp-theme-json.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,6 +4202,9 @@ public function get_styles_for_block( $block_metadata ) {
42024202
$style_variation_responsive_pseudo_css = array();
42034203
$style_variation_layout_metadata = array();
42044204
if ( ! $media_query && ! empty( $block_metadata['variations'] ) ) {
4205+
// A block pseudo node lists the variations too, so read the block's resting styles, not `$node`.
4206+
$variation_block_node = _wp_array_get( $this->theme_json, array_slice( $block_metadata['path'], 0, 3 ), array() );
4207+
42054208
foreach ( $block_metadata['variations'] as $style_variation ) {
42064209
$style_variation_node = _wp_array_get( $this->theme_json, $style_variation['path'], array() );
42074210

@@ -4226,7 +4229,7 @@ public function get_styles_for_block( $block_metadata ) {
42264229
$style_variation_declarations[ $style_variation['selector'] ] = self::get_state_declarations_with_text_clip_escapes(
42274230
static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json ),
42284231
$style_variation_node,
4229-
array( $node, $text_clip_base_block_styles )
4232+
array( $variation_block_node, $text_clip_base_block_styles )
42304233
);
42314234

42324235
// Process pseudo-selectors for this variation (e.g., :hover, :focus)
@@ -4300,7 +4303,7 @@ public function get_styles_for_block( $block_metadata ) {
43004303
$breakpoint_declarations = self::get_state_declarations_with_text_clip_escapes(
43014304
$breakpoint_declarations,
43024305
$breakpoint_node,
4303-
array( $style_variation_node, $node, $text_clip_base_block_styles )
4306+
array( $style_variation_node, $variation_block_node, $text_clip_base_block_styles )
43044307
);
43054308
if ( ! empty( $breakpoint_declarations ) ) {
43064309
$base_ruleset = static::to_ruleset( ':root :where(' . $style_variation['selector'] . ')', $breakpoint_declarations );

‎tests/phpunit/tests/block-supports/block-style-variations.php‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -802,43 +802,6 @@ public function test_block_style_variation_inner_block_text_color_escapes_block_
802802
);
803803
}
804804

805-
/**
806-
* Tests that a variation box clip drops the inherited block type text gradient.
807-
*
808-
* @ticket XXXXX
809-
*
810-
* @covers ::wp_render_block_style_variation_support_styles
811-
*/
812-
public function test_block_style_variation_box_clip_unsets_block_type_text_gradient() {
813-
switch_theme( 'block-theme' );
814-
register_block_style(
815-
'core/paragraph',
816-
array(
817-
'name' => 'clip-box',
818-
'style_data' => array(
819-
'background' => array(
820-
'backgroundClip' => 'border-box',
821-
),
822-
),
823-
)
824-
);
825-
826-
try {
827-
$actual = $this->render_variation_styles_with_block_type_styles(
828-
'core/paragraph',
829-
'is-style-clip-box',
830-
self::get_text_gradient_block_type_styles( 'core/paragraph' )
831-
);
832-
} finally {
833-
unregister_block_style( 'core/paragraph', 'clip-box' );
834-
}
835-
836-
$this->assertMatchesRegularExpression(
837-
'/:root :where\(p\.is-style-clip-box--\d+\)\{[^}]*background-image: unset;[^}]*\}/',
838-
$actual
839-
);
840-
}
841-
842805
/**
843806
* Tests that a variation breakpoint text color refills the letters over a
844807
* block type text gradient.

‎tests/phpunit/tests/theme/wpThemeJson.php‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,61 @@ public function test_variation_pseudo_state_reads_the_block_clip() {
16861686
);
16871687
}
16881688

1689+
/**
1690+
* @ticket XXXXX
1691+
*/
1692+
public function test_variation_rule_from_a_pseudo_node_ignores_the_pseudo_clip() {
1693+
register_block_style(
1694+
'core/button',
1695+
array(
1696+
'name' => 'flashy',
1697+
'label' => 'Flashy',
1698+
)
1699+
);
1700+
1701+
$theme_json = new WP_Theme_JSON(
1702+
array(
1703+
'version' => WP_Theme_JSON::LATEST_SCHEMA,
1704+
'styles' => array(
1705+
'blocks' => array(
1706+
'core/button' => array(
1707+
'background' => array(
1708+
'gradient' => 'linear-gradient(135deg,#ff0000,#0000ff)',
1709+
),
1710+
':hover' => array(
1711+
'background' => array( 'backgroundClip' => 'text' ),
1712+
),
1713+
'variations' => array(
1714+
'flashy' => array(
1715+
'background' => array( 'backgroundClip' => 'padding-box' ),
1716+
),
1717+
),
1718+
),
1719+
),
1720+
),
1721+
)
1722+
);
1723+
1724+
$actual_styles = $theme_json->get_styles_for_block(
1725+
array(
1726+
'name' => 'core/button',
1727+
'path' => array( 'styles', 'blocks', 'core/button', ':hover' ),
1728+
'selector' => '.wp-block-button:hover',
1729+
'css' => '.wp-block-button:hover',
1730+
'variations' => array(
1731+
array(
1732+
'path' => array( 'styles', 'blocks', 'core/button', 'variations', 'flashy' ),
1733+
'selector' => '.is-style-flashy.wp-block-button',
1734+
),
1735+
),
1736+
)
1737+
);
1738+
1739+
unregister_block_style( 'core/button', 'flashy' );
1740+
1741+
$this->assertStringNotContainsString( 'background-image: unset', $actual_styles );
1742+
}
1743+
16891744
/**
16901745
* @ticket 66094
16911746
*/

0 commit comments

Comments
 (0)