Skip to content

fix(ui): preserve 0 as valid coordinate for focal point - #18219

Open
nataliausoltseva wants to merge 1 commit into
payloadcms:3.xfrom
nataliausoltseva:fix/upload-focal-point-zero
Open

nataliausoltseva wants to merge 1 commit into
payloadcms:3.xfrom
nataliausoltseva:fix/upload-focal-point-zero

Conversation

@nataliausoltseva

Copy link
Copy Markdown

What?

Replaces logical OR (||) fallback checks with nullish coalescing (??) when resolving initialFocalPoint coordinates (x and y) in packages/ui/src/elements/Upload/index.tsx.

Why?

When an image focal point coordinate ($x$ or $y$) is set to 0 (e.g. aligning to the far left or top edge of an image), the previous || operator treats 0 as a falsy value. This causes the focal coordinate to unintentionally default back to 50.

How?

Using nullish coalescing (??) ensures that explicit 0 values are respected while still falling back to data?.focal* or 50 when the values are strictly null or undefined.

Before:

initialFocalPoint={{
  x: uploadEdits?.focalPoint?.x || data?.focalX || 50,
  y: uploadEdits?.focalPoint?.y || data?.focalY || 50,
}}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant