Skip to content

Commit

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

const onDimensionChange = ( 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;
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;
}
onChange( nextValue );
};

Expand Down

0 comments on commit 7a960f1

Please sign in to comment.