Created
September 25, 2017 23:36
-
-
Save sampotts/707ed00f59c316e1e9872254db8e1d2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ========================================================================== | |
// tab-focus.js | |
// Detect keyboard tabbing | |
// ========================================================================== | |
(function() { | |
var className = "tab-focus"; | |
// Remove class on blur | |
document.addEventListener("focusout", function(event) { | |
event.target.classList.remove(className); | |
}); | |
// Add classname to tabbed elements | |
document.addEventListener("keydown", function(event) { | |
if (event.keyCode !== 9) { | |
return; | |
} | |
// Delay the adding of classname until the focus has changed | |
// This event fires before the focusin event | |
window.setTimeout(function() { | |
document.activeElement.classList.add(className); | |
}, 0); | |
}); | |
})(); |
Cool, man. Thank you! :3 🥇
All good. Glad it helped, mate!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, man. Thank you! :3 🥇