Skip to content

Commit

Permalink
Background image support: Fix issue with background position if keybo…
Browse files Browse the repository at this point in the history
…ard entry happens before mouse interaction (#59050)

Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
  • Loading branch information
3 people authored and youknowriad committed Feb 20, 2024
1 parent 9438268 commit d6fdcdf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/block-editor/src/hooks/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,14 @@ function backgroundSizeHelpText( value ) {
}

export const coordsToBackgroundPosition = ( value ) => {
if ( ! value || isNaN( value.x ) || isNaN( value.y ) ) {
if ( ! value || ( isNaN( value.x ) && isNaN( value.y ) ) ) {
return undefined;
}

return `${ value.x * 100 }% ${ value.y * 100 }%`;
const x = isNaN( value.x ) ? 0.5 : value.x;
const y = isNaN( value.y ) ? 0.5 : value.y;

return `${ x * 100 }% ${ y * 100 }%`;
};

export const backgroundPositionToCoords = ( value ) => {
Expand Down

0 comments on commit d6fdcdf

Please sign in to comment.