Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cropper component cannot move to the edges of an image when used inside a modal. #428

Closed
Dinishka opened this issue Dec 6, 2022 · 9 comments

Comments

@Dinishka
Copy link

Dinishka commented Dec 6, 2022

Describe the bug
I am using react-easy-crop with mantine components. Currently I am loading the cropper component inside a mantine modal. The issue is when the cropper is loaded inside a modal, I can't move it to the edges of the selected image (it's like padded). One thing I noticed is that when I open the modal and then open the console from the same window (from right, left or bottom), the above mentioned issue goes away.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/fervent-pine-xiucoj
  2. Click on 'Open cropping dialog'
  3. Select an image from the file system
  4. Try to move the cropper to edges of the image

Expected behavior
Should be able to move the cropper anywhere inside the selected image, so we can crop any part form that image.

@ValentinH
Copy link
Owner

This is due to the opening animation of the modal conflicting with the internal logic of the cropper to compute its size.
When you resize the window, it makes the cropper recomputes its size so that's why it fixes the issue.

You can fix this by changing the animation to fade to avoid the cropper size to change while the modal is opening. See this sandbox: https://codesandbox.io/s/gallant-brown-ixjdd3

If you really don't want to change the animation, you need to wait until the animation is complete to actually render the cropper.

@Dinishka
Copy link
Author

Dinishka commented Dec 6, 2022

Thank you so much. Closing this issue because it has resolved with the given solution.

@ljrahn
Copy link

ljrahn commented Sep 15, 2023

oh my thank you. i could have spent hours on this, but luckily i only spent an hour xD

@svarup
Copy link

svarup commented Jun 29, 2024

facing the same issue on shadcn dialog and no way to change the animation to fade

@ValentinH
Copy link
Owner

facing the same issue on shadcn dialog and no way to change the animation to fade

The point of shading/ui is to have the full control in the component code. The animation styles are inside the DialogContent component. Check the different state-open modifiers, there are some related to zoom and translation. Removing them should fix your issue.

@svarup
Copy link

svarup commented Jun 29, 2024

Thank you for your response, if we have a method like resetCropSize() then we can easily call it after dialog or model open, because if we have implemented rotation then on rotate it will suddenly fix the issue

@ValentinH
Copy link
Owner

One way to do this is to add a key prop to the Cropper and change its value (like an incrementing number) once the modal is open.
Otherwise, you can conditionally render the Cropper only when the modal is open.

@svarup
Copy link

svarup commented Jun 30, 2024

One way to do this is to add a key prop to the Cropper and change its value (like an incrementing number) once the modal is open. Otherwise, you can conditionally render the Cropper only when the modal is open.

render cropper after the dialog gets open and with some(100 milliseconds) setTimeout delay resolved this issue

@ValentinH
Copy link
Owner

A nice way to avoid a flash from empty content to the Cropper is to render a plain image by default.

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

No branches or pull requests

4 participants