react-images icon indicating copy to clipboard operation
react-images copied to clipboard

preventScroll not working in v1

Open alec-francis opened this issue 6 years ago • 2 comments

Good day,

In versions 0.x I had to set the prop below to stop the page from scrolling to the top whenever the lightbox was opened. This prop has a default value of true.

preventScroll={false}

Unfortunately, this trick no longer works in v1 so even with this prop set I'm still experiencing the automatic scroll to the top of the page.

Is anyone else experiencing this?

Here is my JSX:

<ModalGateway>
  {this.state.lightboxIsOpen && (
  <Modal
    allowFullscreen={false}
    onClose={this.closeLightbox}
    closeOnBackdropClick={true}
  >
    <Lightbox
      currentIndex={this.state.currentImage}
      views={this.props.images}
      components={{ View }}
      preventScroll={false}
    />
  </Modal>
  )}
</ModalGateway>

Cheers,

Alec

alec-francis avatar Aug 22 '19 09:08 alec-francis

Update

I had a look at the source code and noticed the prop doesn't exist. Would the project like me to submit a PR to implement it?

I think it should be a one-liner. Changing the line:

<ScrollLock />

To this:

{this.props.preventScroll && <ScrollLock />}

Cheers,

Alec

alec-francis avatar Aug 22 '19 10:08 alec-francis

@alec-francis I attempted your one-liner fix, but it does not work. Did you find a workaround?

lablancas avatar May 27 '20 00:05 lablancas