Skip to content

Commit f2c6e31

Browse files
committed
Ensure that the default position 50% 0 is set when changing/uploading images via the media library.
1 parent aa0019b commit f2c6e31

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,22 @@ function BackgroundImageToolsPanelItem( {
245245
return;
246246
}
247247

248+
const sizeValue = style?.background?.backgroundSize;
249+
const positionValue = style?.background?.backgroundPosition;
250+
248251
onChange(
249-
setImmutably( style, [ 'background', 'backgroundImage' ], {
250-
url: media.url,
251-
id: media.id,
252-
source: 'file',
253-
title: media.title || undefined,
252+
setImmutably( style, [ 'background' ], {
253+
...style?.background,
254+
backgroundImage: {
255+
url: media.url,
256+
id: media.id,
257+
source: 'file',
258+
title: media.title || undefined,
259+
},
260+
backgroundPosition:
261+
! positionValue && ( 'auto' === sizeValue || ! sizeValue )
262+
? '50% 0'
263+
: positionValue,
254264
} )
255265
);
256266
};

0 commit comments

Comments
 (0)