Skip to content

Commit

Permalink
Spacing presets: fix bug with select control adding undefined preset …
Browse files Browse the repository at this point in the history
…values (#53005)
  • Loading branch information
glendaviesnz authored Jul 27, 2023
1 parent aad2b74 commit 2704078
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2704078

Please sign in to comment.