Skip to content

Commit fbcae72

Browse files
committed
Merge pull request usablica#340 from connyay/issue-337
reset focus and make enter key behavior more sane
2 parents 7a59063 + 42e4311 commit fbcae72

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

intro.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,23 @@
203203
} else if(e.keyCode === 37) {
204204
//left arrow
205205
_previousStep.call(self);
206-
} else if (e.keyCode === 39 || e.keyCode === 13) {
207-
//right arrow or enter
206+
} else if (e.keyCode === 39) {
207+
//right arrow
208208
_nextStep.call(self);
209+
} else if (e.keyCode === 13) {
210+
//srcElement === ie
211+
var target = e.target || e.srcElement;
212+
if (target && target.className.indexOf('introjs-prevbutton') > 0) {
213+
//user hit enter while focusing on previous button
214+
_previousStep.call(self);
215+
} else if (target && target.className.indexOf('introjs-skipbutton') > 0) {
216+
//user hit enter while focusing on skip button
217+
_exitIntro.call(self, targetElm);
218+
} else {
219+
//default behavior for responding to enter
220+
_nextStep.call(self);
221+
}
222+
209223
//prevent default behaviour on hitting Enter, to prevent steps being skipped in some browsers
210224
if(e.preventDefault) {
211225
e.preventDefault();
@@ -736,6 +750,15 @@
736750
//show the tooltip
737751
oldtooltipContainer.style.opacity = 1;
738752
if (oldHelperNumberLayer) oldHelperNumberLayer.style.opacity = 1;
753+
754+
//reset button focus
755+
if (nextTooltipButton.tabIndex === -1) {
756+
//tabindex of -1 means we are at the end of the tour - focus on skip / done
757+
skipTooltipButton.focus();
758+
} else {
759+
//still in the tour, focus on next
760+
nextTooltipButton.focus();
761+
}
739762
}, 350);
740763

741764
} else {
@@ -886,14 +909,19 @@
886909
_disableInteraction.call(self);
887910
}
888911

912+
prevTooltipButton.removeAttribute('tabIndex');
913+
nextTooltipButton.removeAttribute('tabIndex');
914+
889915
if (this._currentStep == 0 && this._introItems.length > 1) {
890916
prevTooltipButton.className = 'introjs-button introjs-prevbutton introjs-disabled';
917+
prevTooltipButton.tabIndex = '-1';
891918
nextTooltipButton.className = 'introjs-button introjs-nextbutton';
892919
skipTooltipButton.innerHTML = this._options.skipLabel;
893920
} else if (this._introItems.length - 1 == this._currentStep || this._introItems.length == 1) {
894921
skipTooltipButton.innerHTML = this._options.doneLabel;
895922
prevTooltipButton.className = 'introjs-button introjs-prevbutton';
896923
nextTooltipButton.className = 'introjs-button introjs-nextbutton introjs-disabled';
924+
nextTooltipButton.tabIndex = '-1';
897925
} else {
898926
prevTooltipButton.className = 'introjs-button introjs-prevbutton';
899927
nextTooltipButton.className = 'introjs-button introjs-nextbutton';

0 commit comments

Comments
 (0)