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 d6b2fa2b4850bd..a631cbfcff3ef1 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 @@ -49,7 +49,15 @@ describe( 'getCustomValueFromPreset', () => { } ); describe( 'getPresetValueFromCustomValue', () => { - const spacingSizes = [ { name: 'Small', slug: 20, size: '8px' } ]; + const spacingSizes = [ + { name: 'Default', slug: 'default', size: undefined }, + { name: 'Small', slug: 20, size: '8px' }, + ]; + it( 'should return undefined even if an undefined value exist in spacing sizes as occurs if spacingSizes has > 7 entries', () => { + expect( getPresetValueFromCustomValue( undefined, spacingSizes ) ).toBe( + undefined + ); + } ); it( 'should return original value if a string in spacing presets var format', () => { expect( getPresetValueFromCustomValue( 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 340abb0322e9a2..7ca0e1b6f660fd 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/utils.js +++ b/packages/block-editor/src/components/spacing-sizes-control/utils.js @@ -101,8 +101,8 @@ export function getCustomValueFromPreset( value, spacingSizes ) { * @return {string} The preset value if it can be found. */ export function getPresetValueFromCustomValue( value, spacingSizes ) { - // Return value as-is if it is already a preset; - if ( isValueSpacingPreset( value ) || value === '0' ) { + // Return value as-is if it is undefined or is already a preset, or '0'; + if ( ! value || isValueSpacingPreset( value ) || value === '0' ) { return value; }