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
  • Loading branch information
andrewserong committed Feb 15, 2024
1 parent dffac59 commit c3cd8ce
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 c3cd8ce

Please sign in to comment.