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

Skip a step if element in attachTo is not visible #1452

Closed
yonkov opened this issue May 9, 2021 · 5 comments
Closed

Skip a step if element in attachTo is not visible #1452

yonkov opened this issue May 9, 2021 · 5 comments
Labels

Comments

@yonkov
Copy link

yonkov commented May 9, 2021

My tour got stuck when I attached an element that is hidden on mobile. For example, this could be a menu item from collapsed menu on mobile. I need a way to detect if element is hidden from the screen (opacity:0 or display: none, etc.) and if it is hidden, either detach the step from the element or skip the step. Is there a way to do it? I read about the beforeShowPromise but not sure how to implement it.

@yonkov
Copy link
Author

yonkov commented May 9, 2021

I came up with the following logic. It seems to be working, though I am not sure it covers all the use cases:

            beforeShowPromise: () => new Promise((resolve) => {
                    const currentIndex = tour.steps.indexOf(tour.getCurrentStep());
                    let currentStep ='';
                    setTimeout(() => {
                        currentStep = tour.steps[currentIndex].el;
                        if (currentStep.hasAttribute('data-popper-reference-hidden')) {
                            tour.next();
                        }                
                    }, 100);
                    resolve();
            })

@chuckcarpenter
Copy link
Member

@yonkov that looks like a good implementation. You could probably use getComputedStyle on the element as well to check opacity:0 or display: none, etc, as you'd mentioned. Either way, using that hook for custom functionality is what we'd recommend and not something we'd implement in the library directly.

@RobbieTheWagner
Copy link
Member

@chuckcarpenter we do need a sane default for when the element is not found. Right now, we do not show the step, but we do show the modal, so the user is stuck, which feels like a bug.

@chuckcarpenter
Copy link
Member

@rwwagner90 not sure because what is that? Does the tour fail or do we go to the next step? Do we need to add a hook in to override that behavior as well?

@RobbieTheWagner
Copy link
Member

@chuckcarpenter we are discussing the issue here #1437 if you want to weigh in

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

No branches or pull requests

3 participants