Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacing presets: fix bug with select control adding undefined preset values #53005

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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