Skip to content

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

@tonykiselis

Description

@tonykiselis

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions