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

Lightbox close toggler state not properly updating #232

Open
exitsimulation opened this issue Feb 10, 2023 · 7 comments
Open

Lightbox close toggler state not properly updating #232

exitsimulation opened this issue Feb 10, 2023 · 7 comments

Comments

@exitsimulation
Copy link

exitsimulation commented Feb 10, 2023

Hello!

What's the intended behaviour when closing the lightbox? I thought fslightbox would take care about the toggler state on close, however this seems not to be the case? I then tried to flipping the toggle state in the onClose callback, however, this leads to the lightbox opening again immediately and only after a second close the lightbox closes successfully.

What is the best way to implement the closing behaviour properly? Thanks

const [lightboxOpen, setLightboxOpen] = useState(false);

[...]

{image_slider && imagesLightbox && (
          <FsLightbox
            toggler={lightboxOpen}
            sources={imagesLightbox}
            onClose={() => {
              setLightboxOpen(false);
            }}
          />
        )}```
@MariuszRogowicz
Copy link

same problem here - The toggler does not update the shutdown state on its own, but only the change. When we try to override this with the onClose event, the component rerender again.

@exitsimulation
Copy link
Author

@banthagroup Any info on what would be the best approach here? Thanks

@deepkmal
Copy link

I'm running into the same problem as well - any info on how to proceed would be greatly appreciated

@PapaLimaZulu
Copy link

The workaround:

In setUpLightboxUpdater (1/c/main-component/updating)

replace

if (previousProps.toggler !== currentProps.toggler) {

with

if (currentProps.toggler && previousProps.toggler !== currentProps.toggler) {

@27leaves
Copy link

I got it (for all who are as confused as I am). This toggle state is really a toggle and not a "is visible" flag. So, everytime you change the toggler it will open the view. That's why onClose={() => {setLightboxOpen(false); }} will open the view again and seems broken. It's a bit of a confusing API, but as soon as you got it it works.

So the solution is not to do anything onClose, but have it like this:

const [lightboxToggle, setLightboxToggle] = useState(false);

[...]
const openLightbox = () => {
   setLightboxToggle(!lightboxToggle);
}

{image_slider && imagesLightbox && (
          <FsLightbox
            toggler={lightboxToggle}
            sources={imagesLightbox}
            //onClose={() => {
            //  setLightboxOpen(false);
            //}}
          />
        )}

@deshabhishek007
Copy link

Thanks @27leaves it worked.

I got it (for all who are as confused as I am). This toggle state is really a toggle and not a "is visible" flag. So, everytime you change the toggler it will open the view. That's why onClose={() => {setLightboxOpen(false); }} will open the view again and seems broken. It's a bit of a confusing API, but as soon as you got it it works.

So the solution is not to do anything onClose, but have it like this:

const [lightboxToggle, setLightboxToggle] = useState(false);

[...]
const openLightbox = () => {
   setLightboxToggle(!lightboxToggle);
}

{image_slider && imagesLightbox && (
          <FsLightbox
            toggler={lightboxToggle}
            sources={imagesLightbox}
            //onClose={() => {
            //  setLightboxOpen(false);
            //}}
          />
        )}

@Mrrvm
Copy link

Mrrvm commented Feb 8, 2024

Hello!

I have a similar problem, I have implemented exactly what is here and works, but when I try to open the lightbox for the second time, it won't work anymore, because the toggler value does not get updated. Any ideas? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants