Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31ea57d

Browse files
Invader444DanielSchuech
authored andcommitted
Fix keyboard navigation issues.
Pressing left arrow key or enter while focused on the previous button when on the first step will no longer throw an error. Pressing right arrow key or enter while focused o nthe next button when on the last step will no longer throw an error. Pressing enter on the skip button will now properly call onskip instead of oncomplete.
1 parent ca1240b commit 31ea57d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

intro.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,20 +314,26 @@
314314
_exitIntro.call(this, this._targetElement);
315315
} else if (code === 'ArrowLeft' || code === 37) {
316316
//left arrow
317-
_previousStep.call(this);
317+
if (this._currentStep !== 0 && this._introItems.length > 1) {
318+
_previousStep.call(this);
319+
}
318320
} else if (code === 'ArrowRight' || code === 39) {
319321
//right arrow
320-
_nextStep.call(this);
322+
if (this._introItems.length - 1 !== this._currentStep && this._introItems.length > 1) {
323+
_nextStep.call(this);
324+
}
321325
} else if (code === 'Enter' || code === 13) {
322326
//srcElement === ie
323327
var target = e.target || e.srcElement;
324328
if (target && target.className.match('introjs-prevbutton')) {
325329
//user hit enter while focusing on previous button
326-
_previousStep.call(this);
330+
if (this._currentStep !== 0 && this._introItems.length > 1) {
331+
_previousStep.call(this);
332+
}
327333
} else if (target && target.className.match('introjs-skipbutton')) {
328334
//user hit enter while focusing on skip button
329-
if (this._introItems.length - 1 === this._currentStep && typeof (this._introCompleteCallback) === 'function') {
330-
this._introCompleteCallback.call(this);
335+
if (typeof (this._introSkipCallback) === 'function') {
336+
this._introSkipCallback.call(this);
331337
}
332338

333339
_exitIntro.call(this, this._targetElement);
@@ -336,7 +342,9 @@
336342
target.click();
337343
} else {
338344
//default behavior for responding to enter
339-
_nextStep.call(this);
345+
if (this._introItems.length - 1 !== this._currentStep && this._introItems.length > 1) {
346+
_nextStep.call(this);
347+
}
340348
}
341349

342350
//prevent default behaviour on hitting Enter, to prevent steps being skipped in some browsers

0 commit comments

Comments
 (0)