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

showOn not functioning as expected #1814

Closed
mikeCGrant opened this issue Feb 17, 2022 · 5 comments
Closed

showOn not functioning as expected #1814

mikeCGrant opened this issue Feb 17, 2022 · 5 comments
Labels

Comments

@mikeCGrant
Copy link

mikeCGrant commented Feb 17, 2022

In the documentation the showOn property description is as follows:
A function that, when it returns true, will show the step. If it returns false, the step will be skipped.

What I'm seeing:
Setting the return of showOn to false in the first step prevents rendering of any following step/s.
This can be seen from the following code:

var tour = new Shepherd.Tour({
    useModalOverlay: true,
    steps: [
        {
            showOn: function() {
                return false;
            },
            title: 'Title',
            buttons: [
                {
                    text: 'Next',
                    action() { return this.next(); }
                }
            ]
        },
        {
            title: 'Title 2',
            buttons: [
                {
                    text: 'Next',
                    action() { return this.next(); }
                }
            ]
        }
    ]
});
tour.start();
@RobbieTheWagner
Copy link
Member

@mikeCGrant I wonder if this is an edge case or an off by one issue. If the next step is the last step, and it is skipped, we call tour.complete() https://github.com/shipshapecode/shepherd/blob/master/src/js/tour.js#L356

@mikeCGrant
Copy link
Author

mikeCGrant commented Feb 17, 2022

@mikeCGrant I wonder if this is an edge case or an off by one issue. If the next step is the last step, and it is skipped, we call tour.complete() https://github.com/shipshapecode/shepherd/blob/master/src/js/tour.js#L356

I tested it with 3 steps too, setting the first to return false in the showOn method and still the subsequent steps didn't render.

I also set step 2 to false to make sure it wasn't a first step only thing, again subsequent steps didn't render.

@liam-jones-lucout
Copy link
Contributor

liam-jones-lucout commented May 25, 2022

I have this issue. It seems to be caused by this logic:

_skipStep(step, forward) {
    const index = this.steps.indexOf(step);
    const nextIndex = forward ? index + 1 : index - 1;

    if (nextIndex === this.steps.length - 1) {
      this.complete();
    } else {
      this.show(nextIndex, forward);
    }
  }

it seems like it should be comparing step.length the index, not nextIndex

I have created a pull request that I believe resolves it: #1931

@RobbieTheWagner
Copy link
Member

Merged the PR and released 9.1.1, please let me know if the issue is fixed!

@liam-jones-lucout
Copy link
Contributor

Thanks for jumping on this so quickly! Will try it out shortly and let you know

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