Skip to content

Commit 9b48e86

Browse files
andrewserongtellthemachines
authored andcommitted
Background image support: Fix issue with background position if keyboard entry happens before mouse interaction (#59050)
Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
1 parent 00f7e12 commit 9b48e86

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/block-editor/src/hooks/background.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,14 @@ function backgroundSizeHelpText( value ) {
374374
}
375375

376376
export const coordsToBackgroundPosition = ( value ) => {
377-
if ( ! value || isNaN( value.x ) || isNaN( value.y ) ) {
377+
if ( ! value || ( isNaN( value.x ) && isNaN( value.y ) ) ) {
378378
return undefined;
379379
}
380380

381-
return `${ value.x * 100 }% ${ value.y * 100 }%`;
381+
const x = isNaN( value.x ) ? 0.5 : value.x;
382+
const y = isNaN( value.y ) ? 0.5 : value.y;
383+
384+
return `${ x * 100 }% ${ y * 100 }%`;
382385
};
383386

384387
export const backgroundPositionToCoords = ( value ) => {

0 commit comments

Comments
 (0)