Skip to content

Commit ccf582a

Browse files
Editor: unset incompatible dimensions styles in viewport states.
Re-adds a missed line from a previous Gutenberg sync to enable unsetting height and min-height when aspect ratio is set for a viewport state, and vice versa. Props isabel_brison, westonruter, marian1, abditsori. Fixes #66275. git-svn-id: https://develop.svn.wordpress.org/trunk@64322 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f167bef commit ccf582a

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎src/wp-includes/block-supports/states.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ function wp_get_block_state_element_selectors( $root_selector ) {
364364
* Adds a compiled state style rule to a rule list.
365365
*
366366
* @since 7.1.0
367+
* @since 7.2.0 Added fallback dimension styles.
367368
*
368369
* @param array $css_rules Style rules.
369370
* @param string $state Pseudo-state selector.
@@ -376,6 +377,8 @@ function wp_add_block_state_style_rule( &$css_rules, $state, $selector, $style,
376377
return;
377378
}
378379

380+
$style = wp_get_state_style_with_fallback_dimension_styles( $style );
381+
379382
$compiled = wp_style_engine_get_styles(
380383
wp_normalize_state_style_for_css_output( $style )
381384
);

‎tests/phpunit/tests/block-supports/states.php‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,51 @@ public function test_hover_border_radius_generates_scoped_css() {
883883
$this->assertSame( $expected, $actual );
884884
}
885885

886+
/**
887+
* Tests that rendered state CSS includes fallback dimension declarations.
888+
*
889+
* @covers ::wp_render_block_states_support
890+
* @covers ::wp_add_block_state_style_rule
891+
*
892+
* @ticket 66275
893+
*/
894+
public function test_responsive_height_generates_aspect_ratio_unset_in_stylesheet() {
895+
$this->ensure_block_registered( 'test/responsive-root-state' );
896+
897+
$block = array(
898+
'blockName' => 'test/responsive-root-state',
899+
'attrs' => array(
900+
'style' => array(
901+
'@mobile' => array(
902+
'dimensions' => array( 'minHeight' => '300px' ),
903+
),
904+
),
905+
),
906+
);
907+
908+
$actual = wp_render_block_states_support( '<div class="wp-block-test">Hello</div>', $block );
909+
$processor = new WP_HTML_Tag_Processor( $actual );
910+
$this->assertTrue( $processor->next_tag() );
911+
912+
$state_class = null;
913+
foreach ( $processor->class_list() as $class_name ) {
914+
if ( str_starts_with( $class_name, 'wp-states-' ) ) {
915+
$state_class = $class_name;
916+
break;
917+
}
918+
}
919+
$this->assertIsString( $state_class, 'Expected a wp-states-* class on the first tag.' );
920+
921+
$actual_stylesheet = wp_style_engine_get_stylesheet_from_context( 'block-supports', array( 'prettify' => false ) );
922+
923+
$this->assertStringContainsString(
924+
"@media (width <= 480px){.{$state_class}{",
925+
$actual_stylesheet
926+
);
927+
$this->assertStringContainsString( 'min-height:300px', $actual_stylesheet );
928+
$this->assertStringContainsString( 'aspect-ratio:unset', $actual_stylesheet );
929+
}
930+
886931
/**
887932
* Tests that multiple states each generate a separate scoped CSS rule.
888933
*

0 commit comments

Comments
 (0)