Skip to content

Commit

Permalink
fixed: using variable before declaration...
Browse files Browse the repository at this point in the history
not sure if this can cause the variable `target`
to go global.
  • Loading branch information
diasbruno committed Nov 15, 2019
1 parent 5dffbf2 commit cec8833
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/helpers/scopeTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default function scopeTab(node, event) {
return;
}

let target;

const shiftKey = event.shiftKey;
const head = tabbable[0];
const tail = tabbable[tabbable.length - 1];
Expand All @@ -20,7 +22,6 @@ export default function scopeTab(node, event) {
target = tail;
}

var target;
if (tail === document.activeElement && !shiftKey) {
target = head;
}
Expand Down Expand Up @@ -62,9 +63,11 @@ export default function scopeTab(node, event) {
x += shiftKey ? -1 : 1;
}

target = tabbable[x];

// If the tabbable element does not exist,
// focus head/tail based on shiftKey
if (typeof tabbable[x] === "undefined") {
if (typeof target === "undefined") {
event.preventDefault();
target = shiftKey ? tail : head;
target.focus();
Expand All @@ -73,5 +76,5 @@ export default function scopeTab(node, event) {

event.preventDefault();

tabbable[x].focus();
target.focus();
}

0 comments on commit cec8833

Please sign in to comment.