Skip to content

feat(image-cropper-web): make initial crop size configurable - #2396

Open
hunter-koppen wants to merge 1 commit into
mendix:mainfrom
hunter-koppen:fix/image-cropper-initial-crop-size
Open

feat(image-cropper-web): make initial crop size configurable#2396
hunter-koppen wants to merge 1 commit into
mendix:mainfrom
hunter-koppen:fix/image-cropper-initial-crop-size

Conversation

@hunter-koppen

Copy link
Copy Markdown
Contributor

Pull request type


Description

The crop box's initial selection (on load, and again on Reset) was hardcoded to
80% of the image, centered, with no way to configure it — see
buildInitialCrop() in utils/initialCrop.ts. For any aspect ratio that
already matches the desired crop, this forces the user to manually resize the
box on every use, since it never starts flush with the edges.

This PR adds an "Initial crop size (%)" property (initialCropSize, integer,
1-100) to control that, threaded through CropAreaImageCropperContainer
ImageCropperStore into the existing buildInitialCrop() calls (initial
load, Reset, and re-seeding on aspect-ratio resolution). Out-of-range/NaN
values fall back to 100 defensively.

Note on the default: I set the default to 100% (the full image) rather
than preserving the old 80%, since a full-image starting box seems like the
more useful default for most crop use cases and removes the "always resize
by hand first" step. That said, this is a behavior change for existing apps
using this widget, so I'm flagging the choice explicitly — happy to default
to 80% instead (or anything else) if you'd prefer to keep it backward
compatible. Either way it's now configurable per widget instance.

What should be covered while testing?

  • Place the widget on a page, leave "Initial crop size (%)" at its default
    (100) → on load, the crop box should cover the entire image edge-to-edge
    (respecting the configured aspect ratio).
  • Set it to e.g. 50 → the box should start centered at 50% of the image.
  • Click Reset → the box should re-seed at the configured percentage, not just
    restore the original image.
  • Existing behavior (aspect ratio, zoom, rotation, grayscale, output
    format/size) is unaffected — covered by the existing + two new unit tests
    in ImageCropper.spec.tsx.

pnpm lint, pnpm test, and tsc --noEmit all pass for this package.

Add an "Initial crop size (%)" property so the crop box no longer
always seeds at a hardcoded 80% of the image on load and on Reset.
Default is 100% (the full image).
@hunter-koppen
hunter-koppen requested a review from a team as a code owner August 21, 2026 16:09
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