Skip to content

Commit

Permalink
Tweak block-editor’s DimensionTool to avoid updating tests`
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Apr 10, 2024
1 parent 29b7dc9 commit 3007db7
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ export default function WidthHeightTool( {
const height = value.height === 'auto' ? '' : value.height ?? '';

const onDimensionChange = ( dimension ) => ( nextDimension ) => {
const nextValue = { ...value };
// Empty strings or undefined may be passed and both represent removing the value.
if ( ! nextDimension ) {
delete nextValue[ dimension ];
} else {
nextValue[ dimension ] = nextDimension;
}
// Readies the nextValue by omitting the dimension to be changed.
const { [ dimension ]: existingDimensionValue, ...nextValue } = value;
// Bails when both nextDimension and its existing value are falsy. This
// can occur when a `onDeselect` callback runs after the state has
// already updated. In such cases calling onChange would be redundant.
if ( ! nextDimension && ! existingDimensionValue ) return;

// Adds dimension only if non-falsy ('' or undefined may be passed).
if ( !! nextDimension ) nextValue[ dimension ] = nextDimension;
onChange( nextValue );
};

Expand Down

0 comments on commit 3007db7

Please sign in to comment.