Last active
March 7, 2016 15:53
-
-
Save AntonTrollback/5135512 to your computer and use it in GitHub Desktop.
Helper for styling tabbed focus states: html.tabbing a:focus { }
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
a { | |
color: rebeccapurple; | |
text-decoration: none; | |
outline: 0; | |
} | |
a:hover, | |
a:active { | |
color: rebeccapurple; | |
text-decoration: underline; | |
} | |
html.tabbing a:focus { | |
outline: 2px solid; | |
text-decoration: none; | |
} |
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
$(function() { | |
var $root = $('html'); | |
var tabbing, code; | |
$(document).on('mousedown keydown', function (e) { | |
if (e.type === 'mousedown') { | |
tabbing = false; | |
return; | |
} | |
code = e.keyCode ? e.keyCode : e.which; | |
if (code == 9) { | |
tabbing = true; | |
} | |
}); | |
$('a, button, input[type="submit"]').on('focus', function (e) { | |
$root.toggleClass('tabbing', tabbing); | |
}); | |
}); |
Using it like this, tabbing never felt better ^.^
/**
* Set a more prominent focus state when navigating using the keyboard
*/
body[data-focus-source] :focus {
outline: none !important;
}
body[data-focus-source="key"] :focus {
outline: 2px solid red !important;
}
/* Focus states for input and textarea elements is styled using borders */
body[data-focus-source="key"] :matches([tabindex="-1"]:focus, input:focus, textarea:focus) {
outline: none !important;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update
Great stuff: http://allyjs.io/api/style/focus-source.html
code: https://github.com/medialize/ally.js/blob/master/src/style/focus-source.js
based on: https://github.com/WICG/modality
@jenshedqvist