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

TypeError when calling _nextStep function on last introItem by pressing right arrow key. #951

Closed
tonykiselis opened this issue Nov 12, 2019 · 2 comments
Labels

Comments

@tonykiselis
Copy link

tonykiselis commented Nov 12, 2019

Description

There is a bug in _nextStep method which results in:

Cannot read property 'element' of undefined

Expected Behavior

_nextStep should not execute when right arrow is pressed while on last item in introItem set.

Actual Behavior

When one uses arrow keys to move through items, after reaching last element on the item set and pressing right arrow key produces an error, because this._currentStep exceeds the this._introItems array, resulting in call on undefined.

Errors and Screenshots (optional)

error_intro_js

Example (recommended)

Press right arrow key while being on last item in the set of Intro js

Environment (optional)

Problem is with code logic, not the environment.

Problem can be solved by simple if check:

    if (typeof (this._currentStepNumber) !== 'undefined') {
      _forEach(this._introItems, function (item, i) {
        if( item.step === this._currentStepNumber ) {
          this._currentStep = i - 1;
          this._currentStepNumber = undefined;
        }
      }.bind(this));
    }

    // added check here before _currentStep mutation
    if (this._introItems.length - 1 < this._currentStep + 1) {
      return;
    }

    if (typeof (this._currentStep) === 'undefined') {
      this._currentStep = 0;
    } else {
      ++this._currentStep;
    }
@Adifmac
Copy link

Adifmac commented Dec 12, 2019

This does not throw an error, but ignores the user expectation, it should close the intro.
In case you want to close intro - simply add exit command:
// added check here before _currentStep mutation if (this._introItems.length - 1 < this._currentStep + 1) { this.exit(); return; }

@stale
Copy link

stale bot commented Oct 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

2 participants