Skip to content

Commit dbcd12d

Browse files
♿ Add checks on focusable elements to include target element
1 parent 6c00f61 commit dbcd12d

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

shepherd.js/src/components/shepherd-element.svelte

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,19 @@
8383
*/
8484
const handleKeyDown = (e) => {
8585
const { tour } = step;
86+
console.log('tour', e, focusableElements, document.activeElement);
87+
8688
switch (e.keyCode) {
8789
case KEY_TAB:
8890
if (focusableElements.length === 0) {
8991
e.preventDefault();
92+
// If no focusable elements in dialog, focus the highlighted element
93+
if (step.target) {
94+
step.target.focus();
95+
}
9096
break;
9197
}
98+
9299
// Backward tab
93100
if (e.shiftKey) {
94101
if (
@@ -100,10 +107,18 @@
100107
}
101108
} else {
102109
if (document.activeElement === lastFocusableElement) {
110+
e.preventDefault();
111+
// Focus target element when tabbing forward from last element
112+
if (step.target) {
113+
step.target.focus();
114+
} else {
115+
firstFocusableElement.focus();
116+
}
117+
} else if (document.activeElement === step.target) {
103118
e.preventDefault();
104119
firstFocusableElement.focus();
105120
}
106-
}
121+
}
107122
break;
108123
case KEY_ESC:
109124
if (tour.options.exitOnEsc) {

0 commit comments

Comments
 (0)