Skip to content

Instantly share code, notes, and snippets.

@berkin
Created December 1, 2016 06:32
Show Gist options
  • Save berkin/54eaddb898cf7971ec078b40606e15a7 to your computer and use it in GitHub Desktop.
Save berkin/54eaddb898cf7971ec078b40606e15a7 to your computer and use it in GitHub Desktop.
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