diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php index 28a16190d00a1..fbc6a2cdd3094 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php @@ -1212,7 +1212,7 @@ public function set_spacing_sizes() { $below_sizes[] = array( /* translators: %s: Multiple of t-shirt sizing, eg. 2X-Small */ 'name' => $x === $steps_mid_point - 1 ? __( 'Small', 'gutenberg' ) : sprintf( __( '%sX-Small', 'gutenberg' ), strval( $x_small_count ) ), - 'slug' => $slug, + 'slug' => (string) $slug, 'size' => round( $current_step, 2 ) . $unit, ); @@ -1231,7 +1231,7 @@ public function set_spacing_sizes() { $below_sizes[] = array( 'name' => __( 'Medium', 'gutenberg' ), - 'slug' => 50, + 'slug' => '50', 'size' => $spacing_scale['mediumStep'] . $unit, ); @@ -1249,7 +1249,7 @@ public function set_spacing_sizes() { $above_sizes[] = array( /* translators: %s: Multiple of t-shirt sizing, eg. 2X-Large */ 'name' => 0 === $x ? __( 'Large', 'gutenberg' ) : sprintf( __( '%sX-Large', 'gutenberg' ), strval( $x_large_count ) ), - 'slug' => $slug, + 'slug' => (string) $slug, 'size' => round( $current_step, 2 ) . $unit, ); diff --git a/packages/block-editor/src/components/spacing-sizes-control/test/utils.js b/packages/block-editor/src/components/spacing-sizes-control/test/utils.js index a820927a2a073..f893ce021e3cf 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/test/utils.js +++ b/packages/block-editor/src/components/spacing-sizes-control/test/utils.js @@ -57,7 +57,7 @@ describe( 'getSpacingPresetSlug', () => { expect( getSpacingPresetSlug( 'default' ) ).toBe( 'default' ); } ); it( 'should return the int value of the slug portion of a valid preset var', () => { - expect( getSpacingPresetSlug( 'var:preset|spacing|20' ) ).toBe( 20 ); + expect( getSpacingPresetSlug( 'var:preset|spacing|20' ) ).toBe( '20' ); } ); } ); diff --git a/packages/block-editor/src/components/spacing-sizes-control/utils.js b/packages/block-editor/src/components/spacing-sizes-control/utils.js index 12071e3c63dc4..27e6f2e7609ef 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/utils.js +++ b/packages/block-editor/src/components/spacing-sizes-control/utils.js @@ -36,7 +36,9 @@ export function getCustomValueFromPreset( value, spacingSizes ) { } const slug = getSpacingPresetSlug( value ); - const spacingSize = spacingSizes.find( ( size ) => size.slug === slug ); + const spacingSize = spacingSizes.find( + ( size ) => String( size.slug ) === slug + ); return spacingSize?.size; } @@ -80,7 +82,7 @@ export function getSpacingPresetSlug( value ) { const slug = value.match( /var:preset\|spacing\|(.+)/ ); - return slug ? parseInt( slug[ 1 ], 10 ) : undefined; + return slug ? slug[ 1 ] : undefined; } /** @@ -100,7 +102,7 @@ export function getSliderValueFromPreset( presetValue, spacingSizes ) { ? '0' : getSpacingPresetSlug( presetValue ); const sliderValue = spacingSizes.findIndex( ( spacingSize ) => { - return spacingSize.slug === slug; + return String( spacingSize.slug ) === slug; } ); // Returning NaN rather than undefined as undefined makes range control thumb sit in center diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 92ab586dbf7d6..993675fd4d4fd 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -780,7 +780,7 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '4rem', ), ), @@ -797,12 +797,12 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '4rem', ), array( 'name' => 'Large', - 'slug' => 60, + 'slug' => '60', 'size' => '5.5rem', ), ), @@ -819,17 +819,17 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'Small', - 'slug' => 40, + 'slug' => '40', 'size' => '2.5rem', ), array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '4rem', ), array( 'name' => 'Large', - 'slug' => 60, + 'slug' => '60', 'size' => '5.5rem', ), ), @@ -846,22 +846,22 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'Small', - 'slug' => 40, + 'slug' => '40', 'size' => '2.5rem', ), array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '4rem', ), array( 'name' => 'Large', - 'slug' => 60, + 'slug' => '60', 'size' => '5.5rem', ), array( 'name' => 'X-Large', - 'slug' => 70, + 'slug' => '70', 'size' => '7rem', ), ), @@ -878,27 +878,27 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'Small', - 'slug' => 40, + 'slug' => '40', 'size' => '2.5rem', ), array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '5rem', ), array( 'name' => 'Large', - 'slug' => 60, + 'slug' => '60', 'size' => '7.5rem', ), array( 'name' => 'X-Large', - 'slug' => 70, + 'slug' => '70', 'size' => '10rem', ), array( 'name' => '2X-Large', - 'slug' => 80, + 'slug' => '80', 'size' => '12.5rem', ), ), @@ -915,27 +915,27 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'X-Small', - 'slug' => 30, + 'slug' => '30', 'size' => '0.67rem', ), array( 'name' => 'Small', - 'slug' => 40, + 'slug' => '40', 'size' => '1rem', ), array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '1.5rem', ), array( 'name' => 'Large', - 'slug' => 60, + 'slug' => '60', 'size' => '2.25rem', ), array( 'name' => 'X-Large', - 'slug' => 70, + 'slug' => '70', 'size' => '3.38rem', ), ), @@ -952,27 +952,27 @@ function data_generate_spacing_scale_fixtures() { 'expected_output' => array( array( 'name' => 'X-Small', - 'slug' => 30, + 'slug' => '30', 'size' => '0.09rem', ), array( 'name' => 'Small', - 'slug' => 40, + 'slug' => '40', 'size' => '0.38rem', ), array( 'name' => 'Medium', - 'slug' => 50, + 'slug' => '50', 'size' => '1.5rem', ), array( 'name' => 'Large', - 'slug' => 60, + 'slug' => '60', 'size' => '6rem', ), array( 'name' => 'X-Large', - 'slug' => 70, + 'slug' => '70', 'size' => '24rem', ), ), diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 25a973d26ff5a..9fef064661d05 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -243,7 +243,7 @@ "type": "string" }, "slug": { - "description": "Kebab-case unique identifier for the space size preset.", + "description": "Unique identifier for the space size preset. For best cross theme compatibility these should be in the form '10','20','30','40','50','60', etc. with '50' representing the 'Medium' size step.", "type": "string" }, "size": {