Created
February 1, 2020 11:14
-
-
Save tsmd/310c37d4c1118a5c21733f9ff4b3646b 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
function rollFocus(backFlag) { | |
let focusIndex | |
const currentIndex = this.tabbableElements.indexOf(document.activeElement) | |
if (currentIndex < 0) { | |
focusIndex = 0 | |
} else { | |
const tabbableLength = this.tabbableElements.length | |
const direction = backFlag ? -1 : 1 | |
focusIndex = (currentIndex + direction + tabbableLength) % tabbableLength | |
} | |
this.focus(this.tabbableElements[focusIndex]) | |
} | |
function focus(element) { | |
if (!element) { | |
return | |
} | |
element.focus() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment