pradel / react-responsive-modal

Simple responsive react modal
https://react-responsive-modal.leopradel.com/
MIT License
604 stars 95 forks source link

After upgrading from 4.1.0 to 6.1 Modal doesn't close after pressing submit/cancel/close button. #482

Closed schraderbachar closed 2 years ago

schraderbachar commented 2 years ago

Bug report

Describe the bug

After I updated the dependency in my project, I can open the modal fine, but when I press cancel/submit/the close button it doens't close even though when I console.log the state of open (im using it as a class component) it says false.

To Reproduce

Open the modal and then press close. I'm using it to add announcements to a web page. It has a text area and a date and time picker as well but I didn't add that to the request.

<Modal classNames={{overlay: modalStyle.overlay}} open={open} onClose={this.onCloseModal} center>

<button key="cancel" id="cancelButton" className={`${modalStyle.formButton} ${modalStyle.red}`} onClick={this.onCloseModal}>
                Cancel
              </button>
              <button key="submit" id="submitButton" className={`${modalStyle.formButton} ${modalStyle.blue}`} onClick={this.addAndCloseModal}>
                Submit
              </button>

state component this.state = { open: false}

My open function.

onOpenModal = () => {
    this.setState({ open: true });
  }

My close function

 onCloseModal = () => {
    console.log(this.state.open);
    this.setState({ open: false }); 
    console.log(this.state.open);
  }

Also for some reason when I first press the close or submit button, both console.logs are the same, they give me the same value (true) when I first click the close/submit button, and not true, then false after the state changes. But on subsequent clicks they both give me false, as they should, but the modal is still open.

Expected behavior

I expect the modal to close when I press cancel/submit/close buttons.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

Additional context

Add any other context about the problem here. This problem only appeared after I updated the dep from 4.1.0 to 6.1.0 and the modal no longer shows as a modal it shows like this. image where as it was showing like this earlier. image

pradel commented 2 years ago

To fix your issue you need to import the css file manually, just add import 'react-responsive-modal/styles.css'; somewhere in your code and it should work after this.