From 7a960f1d126fb349cf4f8c015496abf264621af9 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Wed, 10 Apr 2024 18:01:13 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"Tweak=20block-editor=E2=80=99s=20`Dim?= =?UTF-8?q?ensionTool`=20to=20avoid=20updating=20tests`"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3007db759ee55a7f02114b0f0072c826ab1c164f. --- .../dimensions-tool/width-height-tool.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/components/dimensions-tool/width-height-tool.js b/packages/block-editor/src/components/dimensions-tool/width-height-tool.js index 8d8bba539f5349..6a4609f9a0bf2d 100644 --- a/packages/block-editor/src/components/dimensions-tool/width-height-tool.js +++ b/packages/block-editor/src/components/dimensions-tool/width-height-tool.js @@ -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 ); };