Created
December 1, 2016 06:32
-
-
Save berkin/54eaddb898cf7971ec078b40606e15a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let tabbables; | |
function setTabbable(e) { | |
if (e.keyCode === 9) { | |
e.preventDefault(); | |
// the tabbable elements can be changed. | |
tabbables = Array.prototype.slice.call(tabbable(this.currentStepView)); | |
const isFocused = tabbables.some((item, i) => { | |
if (e.target === item) { | |
if (i === tabbables.length - 1) { | |
tabbables[e.shiftKey ? i - 1 : 0].focus(); | |
} else if (i === 0) { | |
tabbables[e.shiftKey ? 0 : 1].focus(); | |
} else { | |
tabbables[i + (e.shiftKey ? -1 : 1)].focus(); | |
} | |
return true; | |
} | |
return false; | |
}); | |
if (!isFocused) { | |
tabbables[0].focus(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment