diff --git a/src/wp-includes/block-supports/dimensions.php b/src/wp-includes/block-supports/dimensions.php index 381f7bc3fb8be..beb6e374604c6 100644 --- a/src/wp-includes/block-supports/dimensions.php +++ b/src/wp-includes/block-supports/dimensions.php @@ -64,7 +64,7 @@ function wp_apply_dimensions_support( $block_type, $block_attributes ) { } $dimensions_block_styles = array(); - $supported_features = array( 'minHeight', 'height', 'width' ); + $supported_features = array( 'minHeight', 'minWidth', 'height', 'width' ); foreach ( $supported_features as $feature ) { $has_support = block_has_support( $block_type, array( 'dimensions', $feature ), false ); diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 3385d6fe6b62d..e16d8c5600298 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -248,7 +248,7 @@ class WP_Theme_JSON { * @since 6.7.0 Added `background-attachment` property. * @since 7.0.0 Added `dimensions.width` and `dimensions.height`. * Added `text-indent` property. - * @since 7.1.0 Added `text-shadow` property. + * @since 7.1.0 Added `min-width` and `text-shadow`. * @var array */ const PROPERTIES_METADATA = array( @@ -295,6 +295,7 @@ class WP_Theme_JSON { 'margin-bottom' => array( 'spacing', 'margin', 'bottom' ), 'margin-left' => array( 'spacing', 'margin', 'left' ), 'min-height' => array( 'dimensions', 'minHeight' ), + 'min-width' => array( 'dimensions', 'minWidth' ), 'outline-color' => array( 'outline', 'color' ), 'outline-offset' => array( 'outline', 'offset' ), 'outline-style' => array( 'outline', 'style' ), @@ -417,7 +418,7 @@ class WP_Theme_JSON { * Added support for `dimensions.width` and `dimensions.height`. * Added support for `typography.textIndent`. * @since 7.1.0 Added `viewport` property. - * Added support for `background.gradient` and `blockVisibility.allowEditing`. + * Added support for `background.gradient`, `dimensions.minWidth` and `blockVisibility.allowEditing`. * @var array */ const VALID_SETTINGS = array( @@ -460,6 +461,7 @@ class WP_Theme_JSON { 'dimensionSizes' => null, 'height' => null, 'minHeight' => null, + 'minWidth' => null, 'width' => null, ), 'layout' => array( @@ -563,8 +565,8 @@ class WP_Theme_JSON { * @since 6.5.0 Added support for `dimensions.aspectRatio`. * @since 6.6.0 Added `background` sub properties to top-level only. * @since 7.0.0 Added support for `dimensions.width` and `dimensions.height`. - * @since 7.1.0 Added `background.gradient`. - * @since 7.1.0 Added support for `typography.textShadow`. + * @since 7.1.0 Added support for `background.gradient`,`dimensions.minWidth`, + * and `typography.textShadow`. * @var array */ const VALID_STYLES = array( @@ -595,6 +597,7 @@ class WP_Theme_JSON { 'aspectRatio' => null, 'height' => null, 'minHeight' => null, + 'minWidth' => null, 'width' => null, ), 'filter' => array( @@ -1035,6 +1038,7 @@ public static function get_element_class_name( $element ) { * @since 6.5.0 Added `background.backgroundSize` and `dimensions.aspectRatio`. * @since 7.0.0 Added `dimensions.width` and `dimensions.height`. * @since 7.1.0 Added `background.gradient`. + * Added `dimensions.minWidth`. * @var array */ const APPEARANCE_TOOLS_OPT_INS = array( @@ -1052,6 +1056,7 @@ public static function get_element_class_name( $element ) { array( 'dimensions', 'aspectRatio' ), array( 'dimensions', 'height' ), array( 'dimensions', 'minHeight' ), + array( 'dimensions', 'minWidth' ), array( 'dimensions', 'width' ), array( 'position', 'sticky' ), array( 'spacing', 'blockGap' ), diff --git a/src/wp-includes/style-engine/class-wp-style-engine.php b/src/wp-includes/style-engine/class-wp-style-engine.php index 97b9981e598f7..21dea5ea65978 100644 --- a/src/wp-includes/style-engine/class-wp-style-engine.php +++ b/src/wp-includes/style-engine/class-wp-style-engine.php @@ -242,6 +242,15 @@ final class WP_Style_Engine { 'dimension' => '--wp--preset--dimension--$slug', ), ), + 'minWidth' => array( + 'property_keys' => array( + 'default' => 'min-width', + ), + 'path' => array( 'dimensions', 'minWidth' ), + 'css_vars' => array( + 'dimension' => '--wp--preset--dimension--$slug', + ), + ), 'objectFit' => array( 'property_keys' => array( 'default' => 'object-fit', diff --git a/tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.php b/tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.php index 897bcd0dd04f5..6fd58f4e56dec 100644 --- a/tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.php +++ b/tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.php @@ -242,4 +242,75 @@ public function data_height_block_support() { ), ); } + + /** + * Tests that minimum width block support works as expected. + * + * @ticket 65037 + * + * @covers ::wp_apply_dimensions_support + * + * @dataProvider data_minimum_width_block_support + * + * @param string $block_name The test block name to register. + * @param mixed $dimensions The dimensions block support settings. + * @param mixed $expected The expected results. + */ + public function test_minimum_width_block_support( $block_name, $dimensions, $expected ) { + $this->test_block_name = $block_name; + register_block_type( + $this->test_block_name, + array( + 'api_version' => 2, + 'attributes' => array( + 'style' => array( + 'type' => 'object', + ), + ), + 'supports' => array( + 'dimensions' => $dimensions, + ), + ) + ); + $registry = WP_Block_Type_Registry::get_instance(); + $block_type = $registry->get_registered( $this->test_block_name ); + $block_attrs = array( + 'style' => array( + 'dimensions' => array( + 'minWidth' => '200px', + ), + ), + ); + + $actual = wp_apply_dimensions_support( $block_type, $block_attrs ); + + $this->assertSame( $expected, $actual ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_minimum_width_block_support() { + return array( + 'style is applied' => array( + 'block_name' => 'test/min-width-style-is-applied', + 'dimensions' => array( + 'minWidth' => true, + ), + 'expected' => array( + 'style' => 'min-width:200px;', + ), + ), + 'style output is skipped when individual feature serialization is skipped' => array( + 'block_name' => 'test/min-width-with-individual-skipped-serialization-block-supports', + 'dimensions' => array( + 'minWidth' => true, + '__experimentalSkipSerialization' => array( 'minWidth' ), + ), + 'expected' => array(), + ), + ); + } } diff --git a/tests/phpunit/tests/style-engine/styleEngine.php b/tests/phpunit/tests/style-engine/styleEngine.php index 0327ca66bbc6a..fe858e07cb6a7 100644 --- a/tests/phpunit/tests/style-engine/styleEngine.php +++ b/tests/phpunit/tests/style-engine/styleEngine.php @@ -24,6 +24,7 @@ class Tests_wpStyleEngine extends WP_UnitTestCase { * @ticket 62189 * @ticket 63799 * @ticket 64974 + * @ticket 65037 * * @covers ::wp_style_engine_get_styles * @@ -207,7 +208,7 @@ public function data_wp_style_engine_get_styles() { ), ), - 'inline_valid_dimensions_style' => array( + 'inline_valid_dimensions_min_height_style' => array( 'block_styles' => array( 'dimensions' => array( 'minHeight' => '50vh', @@ -222,6 +223,21 @@ public function data_wp_style_engine_get_styles() { ), ), + 'inline_valid_dimensions_min_width_style' => array( + 'block_styles' => array( + 'dimensions' => array( + 'minWidth' => '25vw', + ), + ), + 'options' => null, + 'expected_output' => array( + 'css' => 'min-width:25vw;', + 'declarations' => array( + 'min-width' => '25vw', + ), + ), + ), + 'inline_valid_aspect_ratio_style' => array( 'block_styles' => array( 'dimensions' => array( diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index aee20d50fc125..3e72c7cfbd68a 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -47,6 +47,7 @@ public static function set_up_before_class() { /** * @ticket 52991 * @ticket 54336 + * @ticket 65037 */ public function test_get_settings() { $theme_json = new WP_Theme_JSON( @@ -261,6 +262,9 @@ public function test_get_settings_presets_are_keyed_by_origin() { $this->assertEqualSetsWithIndex( $expected_no_origin, $actual_no_origin ); } + /** + * @ticket 65037 + */ public function test_get_settings_appearance_true_opts_in() { $theme_json = new WP_Theme_JSON( array( @@ -313,6 +317,7 @@ public function test_get_settings_appearance_true_opts_in() { 'aspectRatio' => true, 'height' => true, 'minHeight' => true, + 'minWidth' => true, 'width' => true, ), 'position' => array( @@ -355,6 +360,7 @@ public function test_get_settings_appearance_true_opts_in() { 'aspectRatio' => true, 'height' => true, 'minHeight' => true, + 'minWidth' => true, 'width' => true, ), 'position' => array(