Last active
June 29, 2016 10:09
-
-
Save conorluddy/ff54c657fd5e379f35c7feaea5a41ed3 to your computer and use it in GitHub Desktop.
JS (jQuery) function to add a class to the document once the user hits the tab key. Allows you to use additional styles for accessibility that won't show until tab key has been used. Probably causes issues, use with care.
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
/** | |
* If user hits tab key then we add a class to <html> that lets us use | |
* additional styling hints to show focus etc. | |
*/ | |
function detectTabKey() { | |
$(document).one('keydown', function(e) { | |
if (e.keyCode === 9) { | |
$('html').addClass('is-tab-user'); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment