From cec8833cccb3c2b2580cabcdf8fb244e0a4f2b34 Mon Sep 17 00:00:00 2001 From: Bruno Dias Date: Sat, 26 Oct 2019 20:17:10 -0300 Subject: [PATCH] fixed: using variable before declaration... not sure if this can cause the variable `target` to go global. --- src/helpers/scopeTab.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index 16513c19..d152951b 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -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]; @@ -20,7 +22,6 @@ export default function scopeTab(node, event) { target = tail; } - var target; if (tail === document.activeElement && !shiftKey) { target = head; } @@ -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(); @@ -73,5 +76,5 @@ export default function scopeTab(node, event) { event.preventDefault(); - tabbable[x].focus(); + target.focus(); }