materialize icon indicating copy to clipboard operation
materialize copied to clipboard

Can't scroll after close modal

Open piotrkunicki opened this issue 6 years ago • 6 comments

I'm using version 1.0.0 latest release and have a problem with modals

When the modal is open, <body style="overflow: hidden;"> this css is added to body tag, but it's not removed when I'm closing the modal, so I'm not able to scroll the website then..

The issue is visible on desktop version of Chrome, Firefox, and also mobile (android), I didn't notice the issue on iOS devices.

piotrkunicki avatar Sep 19 '18 14:09 piotrkunicki

Can you provide a codepen so we can reproduce this?

DanielRuf avatar Sep 20 '18 05:09 DanielRuf

The same happens to me.

The problem is when the modal's close method run, the attr isOpen is always false, then the function returns and not follows to the next condition to changes body's style. I solved this adding document.body.style.overflow = '' before return ''' /** * Close Modal */

}, {
  key: "close",
  value: function close() {
    if (!this.isOpen) { //<========= here isOpen is always false
      document.body.style.overflow = ''; // I added this line
      return;
    }

'''

brucegroverlee avatar Sep 29 '18 01:09 brucegroverlee

This workaround fixed it for me:

const options = {
    onCloseEnd() {
      $('body').css('overflow', '')
    }
  }
M.Modal.init(elem, options)

mozfet avatar Oct 17 '18 09:10 mozfet

I can't reproduce this locally. Please submit a codepen that reproduces this issue

acburst avatar Oct 25 '18 23:10 acburst

I'll try to get a codepen up by this weekend.

mozfet avatar Oct 29 '18 12:10 mozfet

having this problem in 2023

alexisrabcarv avatar Oct 13 '23 16:10 alexisrabcarv