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

Screen Glitch When Close Modal #495

Closed
ardyanrizki opened this issue May 11, 2022 · 22 comments · Fixed by #519
Closed

Screen Glitch When Close Modal #495

ardyanrizki opened this issue May 11, 2022 · 22 comments · Fixed by #519
Labels

Comments

@ardyanrizki
Copy link

Bug report

Describe the bug

When closing the modal an unexpected page glitch/blinking screen occurs. The modal still could close completely after that.

To Reproduce

Take action to close the modal either by clicking modal's close button, ESC, or custom button inside modal that calls the close function.

Expected behavior

Modal closes smoothly without any odd blinks.

Screenshots

Screen.Recording.2022-05-11.at.20.22.05.mov

System information

  • Version of react-responsive-modal: ^6.2.0
  • Version of react: 18.1.0
  • Version of next: 12.1.6
  • Version of react-dom": 18.1.0
  • Browser version: Chrome 101.0.4951.54 (Official Build) (arm64), Safari 15.4 (17613.1.17.1.13)

Additional context

This case happens on my web page here. You can clicking the kebab menu (three dots icon) at the top right page to show the modal and then click "Cancel" to close it.

@omkhetwal
Copy link

Temporary fix ( mount|unmount ) modal

{
       open && <Modal />
}
import "./styles.css";

import "react-responsive-modal/styles.css";
import { Modal } from "react-responsive-modal";
import { useState } from "react";

export default function App() {
  const [open, setOpen] = useState(false);

  const onOpenModal = () => setOpen(true);
  const onCloseModal = () => setOpen(false);

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <button onClick={onOpenModal}>Open</button>
      {open && (
        <Modal open={open} onClose={onCloseModal} center>
          <h2>Simple centered modal</h2>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
            pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
            hendrerit risus, sed porttitor quam.
          </p>
        </Modal>
      )}
    </div>
  );
}

@ardyanrizki
Copy link
Author

ardyanrizki commented May 12, 2022

Temporary fix ( mount|unmount ) modal

{
       open && <Modal />
}
import "./styles.css";

import "react-responsive-modal/styles.css";
import { Modal } from "react-responsive-modal";
import { useState } from "react";

export default function App() {
  const [open, setOpen] = useState(false);

  const onOpenModal = () => setOpen(true);
  const onCloseModal = () => setOpen(false);

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <button onClick={onOpenModal}>Open</button>
      {open && (
        <Modal open={open} onClose={onCloseModal} center>
          <h2>Simple centered modal</h2>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
            pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
            hendrerit risus, sed porttitor quam.
          </p>
        </Modal>
      )}
    </div>
  );
}

Thank you for your workaround @omkhetwal. Does this happen often in any case?

@omkhetwal
Copy link

@ardyanrizki I'm not sure, there were more than 4 instances where I had to use Modal in the application, at some place I noticed there wasn't any glitch, then I checked the difference so when I came across your issue, I did the change and worked for me too.
It didn't happen in previous versions of the library though.

@huksley
Copy link
Contributor

huksley commented Jun 13, 2022

I have the same issue (with same versions), any updates on this?

@antosvle
Copy link

Same issue here

@mazzomix
Copy link

mazzomix commented Jul 1, 2022

+1

@laurenskling
Copy link

I blame this on React 18. Started happening to me after upgrading to React 18

@Maciej916
Copy link

Same for me

@huksley
Copy link
Contributor

huksley commented Jul 5, 2022

Some investigations here radix-ui/primitives#1344

@huksley
Copy link
Contributor

huksley commented Jul 5, 2022

I fixed it in a different way, maybe it is worse, but I don't want to unmount component:

const ref = useRef<HTMLDivElement>(null);
return (<Modal
    ref={ref}
    onClose={_ => setOpen(false)}
    onAnimationEnd={() => {
        if (!open) {
          if (ref.current) {
            ref.current.style.opacity = "0%";
          }
          if (ref.current?.parentElement?.parentElement) {
            ref.current.parentElement.parentElement.style.opacity = "0%";
          }
        }
      }}>
     {children}
  </Modal>);

@Maciej916
Copy link

When it will be fixed?

@ArturoDucasse
Copy link

I have the exact same issue, with the versions:

  • node: v18.8.0
  • react: ^18.0.0 (still waiting for Support React 18 #496 to be accepted btw)
  • react-dom: "~18.1.0",
  • react-responsive-modal: ^6.2.0

@AVPletnev
Copy link

AVPletnev commented Sep 17, 2022

I have the exact same issue, with the versions:

  • node: v18.8.0
  • react: ^18.0.0 (still waiting for Support React 18 #496 to be accepted btw)
  • react-dom: "~18.1.0",
  • react-responsive-modal: ^6.2.0

add css
it helped me
.react-responsive-modal-overlay, .react-responsive-modal-container, .react-responsive-modal-modal { animation-fill-mode: forwards!important; }

@Shooshte
Copy link

Same issue with the closing animation, adding the CSS that @AVPletnev posted solved it.

@xyeres
Copy link

xyeres commented Oct 5, 2022

Indeed @AVPletnev's CSS fixed it thanks!

@ardyanrizki
Copy link
Author

Fixed with this one line css. Credit and big thanks to @AVPletnev #495 (comment)

add css it helped me .react-responsive-modal-overlay, .react-responsive-modal-container, .react-responsive-modal-modal { animation-fill-mode: forwards!important; }

@huksley
Copy link
Contributor

huksley commented Oct 31, 2022

I think this PR needs to stay in open state because repo and NPM package is still not fixed.

@irtaza9
Copy link

irtaza9 commented Nov 5, 2022

Fixed with this one line css. Credit and big thanks to @AVPletnev

.react-responsive-modal-overlay,
.react-responsive-modal-container,
.react-responsive-modal-modal {
  animation-fill-mode: forwards !important;
}

@kahlan88
Copy link

This is still an issue in the latest version of the package. While the suggestion helps work around it, the issue is with the package.

@ardyanrizki ardyanrizki reopened this Nov 22, 2022
@Aminehassou
Copy link

Fixed with this one line css. Credit and big thanks to @AVPletnev #495 (comment)

add css it helped me .react-responsive-modal-overlay, .react-responsive-modal-container, .react-responsive-modal-modal { animation-fill-mode: forwards!important; }

This fixes the issue but introduces a different one for me, makes my modal have different color values throughout its window:
#FEFEFE
image

#FFFFFF
image

My guess is this has something to do with the animation not fully completing when using animation-fill-mode: forwards. Causing a slight bit of transparency.

@BansiBrainerHub
Copy link

BansiBrainerHub commented Apr 14, 2023

this one works for me as well!

.react-responsive-modal-modal { animation-fill-mode: forwards !important; }

@Mathias-21
Copy link

same issue

bhj added a commit to bhj/KaraokeEternal that referenced this issue Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.