Skip to content

Cropped area not accounting for zoom of containing elements properly #591

Open
@c0d3ster

Description

@c0d3ster

Bug Description:
I am using ReactCrop as an element/node on a React Flow canvas. The React Flow library allows the entire canvas area to be zoomed on scroll. Whenever the zoom !== 1, it leaves me unable to crop the larger than zoom (when < 1) or able to crop larger than the image (when > 1). I am also scaling the image down from naturalWidth to a set max width with CSS, but the completed crop is properly being calculated so shouldn't be any issues there.

Screenshot 2024-05-29 at 11 02 44 AM

Expected Behavior:
The croppable area selection should always be a maximum of the width and height of the image.

Actual Behavior:
The croppable area selection is only able to go to a maximum of width * zoom or height * zoom. If I try to manually divide by the zoom value during setCrop it causes another issue where the crop area expands while moving the selection.

Minimum Reproducible Example
A minimum reproducible example can be created by adding transform: scale(50%) to the div containing the ReactCrop component then trying to move the crop selection. the selection will only be able to crop up to 50% in the top left of the image

Possible Solutions
There seems to be an issue with the containCrop or clamping logic within the resizeCrop function, so I'm wondering if we can either calculate any zoom value internally using window/document properties or if we can pass in a prop for zoom. This would be different from the scale prop because I still want the image to display without any whitespace and at 1.0 scale.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions