Skip to content

Commit 0f43362

Browse files
committed
Rolling back setting the default to 50% - the UX is not clear. Should we default to 50% every time the user switches to auto? What about after they deliberately clear the input?
Roll back defaultValues prop - unnecessary
1 parent b691a4a commit 0f43362

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

packages/block-editor/src/components/global-styles/background-panel.js

+6-30
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import {
2222
__experimentalItemGroup as ItemGroup,
2323
__experimentalHStack as HStack,
2424
__experimentalTruncate as Truncate,
25-
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
2625
} from '@wordpress/components';
2726
import { __, sprintf } from '@wordpress/i18n';
2827
import { store as noticesStore } from '@wordpress/notices';
2928
import { getFilename } from '@wordpress/url';
30-
import { useCallback, Platform, useRef, useState } from '@wordpress/element';
29+
import { useCallback, Platform, useRef } from '@wordpress/element';
3130
import { useDispatch, useSelect } from '@wordpress/data';
3231
import { focus } from '@wordpress/dom';
3332
import { isBlobURL } from '@wordpress/blob';
@@ -195,14 +194,8 @@ function BackgroundImageToolsPanelItem( {
195194
onChange,
196195
style,
197196
inheritedValue,
198-
defaultValues,
199197
themeFileURIs,
200198
} ) {
201-
const sizeValue =
202-
style?.background?.backgroundSize ||
203-
inheritedValue?.background?.backgroundSize ||
204-
defaultValues?.backgroundSize;
205-
206199
const mediaUpload = useSelect(
207200
( select ) => select( blockEditorStore ).getSettings().mediaUpload,
208201
[]
@@ -253,18 +246,11 @@ function BackgroundImageToolsPanelItem( {
253246
}
254247

255248
onChange(
256-
setImmutably( style, [ 'background' ], {
257-
...style?.background,
258-
backgroundImage: {
259-
url: media.url,
260-
id: media.id,
261-
source: 'file',
262-
title: media.title || undefined,
263-
},
264-
backgroundSize:
265-
'auto' === sizeValue || ! sizeValue
266-
? '50%'
267-
: style?.background?.backgroundSize,
249+
setImmutably( style, [ 'background', 'backgroundImage' ], {
250+
url: media.url,
251+
id: media.id,
252+
source: 'file',
253+
title: media.title || undefined,
268254
} )
269255
);
270256
};
@@ -383,8 +369,6 @@ function BackgroundSizeToolsPanelItem( {
383369
defaultValues,
384370
themeFileURIs,
385371
} ) {
386-
const [ lastKnownImageWidth, setLastKnownImageWidth ] =
387-
useState( undefined );
388372
const sizeValue =
389373
style?.background?.backgroundSize ||
390374
inheritedValue?.background?.backgroundSize;
@@ -457,7 +441,6 @@ function BackgroundSizeToolsPanelItem( {
457441
next === 'auto'
458442
) {
459443
nextRepeat = undefined;
460-
next = lastKnownImageWidth ?? 'auto';
461444
}
462445

463446
/*
@@ -466,7 +449,6 @@ function BackgroundSizeToolsPanelItem( {
466449
*/
467450
if ( ! next && currentValueForToggle === 'auto' ) {
468451
next = 'auto';
469-
setLastKnownImageWidth( undefined );
470452
}
471453

472454
onChange(
@@ -476,11 +458,6 @@ function BackgroundSizeToolsPanelItem( {
476458
backgroundSize: next,
477459
} )
478460
);
479-
480-
const imageWidth = parseQuantityAndUnitFromRawValue( next );
481-
if ( typeof imageWidth?.[ 0 ] !== 'undefined' && imageWidth?.[ 1 ] ) {
482-
setLastKnownImageWidth( next );
483-
}
484461
};
485462

486463
const updateBackgroundPosition = ( next ) => {
@@ -645,7 +622,6 @@ export default function BackgroundPanel( {
645622
isShownByDefault={ defaultControls.backgroundImage }
646623
style={ value }
647624
inheritedValue={ inheritedValue }
648-
defaultValues={ defaultValues }
649625
themeFileURIs={ themeFileURIs }
650626
/>
651627
{ shouldShowBackgroundSizeControls && (

0 commit comments

Comments
 (0)