8000 Mask is does'nt showing the first time · Issue #579 · dominictobias/react-image-crop · GitHub
[go: up one dir, main page]

Skip to content

Mask is does'nt showing the first time #579

Open

Description

@Djibdjib

Hi and thx for this tool !

When i open the crop in a modal, the mask is not showed the first time. If i close the modal and re open, all is perfect...

Thx for your help.

Activity

  1. Djibdjib commented on Feb 6, 2024

    @Djibdjib
    Author

    Ok i found the solution, i use the onLoad attribute on the image to set the crop values. It works !

  2. immanu10 commented on Feb 6, 2024

    @immanu10

    @Djibdjib I'm facing the same issue even though I'm using the onLoad attribute. Do you mind sharing what exactly you did to fix it?

  3. Djibdjib commented on Feb 6, 2024

    @Djibdjib
    Author

    @immanu10 Yeah of course !

    const onImageLoad = () => {
            setCrop({
                unit: "%",
                width: currentFile.crop.w || 50,
                height: currentFile.crop.h || 50,
                x: currentFile.crop.x || 25,
                y: currentFile.crop.y || 25,
            });
        };
    <ReactCrop
                    key={crop}
                    crop={crop}
                    onChange={(c, p) => onChangeCrop(c, p)}
                    className="inline-block rounded-lg"
                    keepSelection={true}
                    ruleOfThirds={true}
                >
                    <img src={currentSrcImage} className="rounded-t-lg" onLoad={onImageLoad} />
                </ReactCrop>
  4. yuhao-wong commented on Feb 14, 2024

    @yuhao-wong

    Adding some context to this - setting the crop onImageLoad didn't work for me.
    The crop dimensions will be correctly set, but the mask itself will be broken.

    If you inspect the DOM when this happens, it seems like the of the mask SVG has 0x0 dimensions.
    I was able to force refresh it on load by doing
    document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")

    I'm curious if there is a better way around this. I am unable to consistently reproduce this issue.
    image

  5. dominictobias commented on Feb 15, 2024

    @dominictobias
    Owner

    Adding some context to this - setting the crop onImageLoad didn't work for me. The crop dimensions will be correctly set, but the mask itself will be broken.

    If you inspect the DOM when this happens, it seems like the of the mask SVG has 0x0 dimensions. I was able to force refresh it on load by doing document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")

    I'm curious if there is a better way around this. I am unable to consistently reproduce this issue. image

    Is this in a modal as well? Does your modal have some opening animation that changes the height?

  6. yuhao-wong commented on Feb 15, 2024

    @yuhao-wong

    Yes its in a modal, but I am rendering it with React.createPortal.
    No animation.

  7. hanurii commented on Aug 30, 2024

    @hanurii

    In my case, the issue was resolved when I didn't provide initial values in the crop's useState.

    const [crop, setCrop] = useState();
  8. ak-pdeshaies commented on Sep 4, 2024

    @ak-pdeshaies

    THANK YOU!!!

    Both proposed solution found here worked for me

    1. document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")
    2. Remove default crop value const [crop, setCrop] = useState();

    I ended up using option 2. FYI, if you need to specify a crop do it on imageLoad with setCrop({ ... }) That's how I'm doing it and I fixed the issue I was having. \o/

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

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

      0