Skip to content

Instantly share code, notes, and snippets.

@mkormendy
Created November 13, 2014 19:41
Show Gist options
  • Save mkormendy/019830f46a0a3abab604 to your computer and use it in GitHub Desktop.
Save mkormendy/019830f46a0a3abab604 to your computer and use it in GitHub Desktop.
A Pen by Mike Kormendy.
<ol>
<li>Press the tab key to activate focus outlines.</li>
<li>Click your mouse anywhere to disable focus outlines.</li>
</ol>
<a href="#1">BUTTON 1</a>
<a href="#2">BUTTON 2</a>
<a href="#3">BUTTON 3</a>

Keyboard Activated Accessibility

This test example attempts to hide accessible styles until they are needed. We provide accessible outline focus styles only when the user uses keyboard input. When the mouse is activated or clicks a link it deactivates accessible styles.

A Pen by Mike Kormendy on CodePen.

License.

this.onkeydown = function (e) {
if (e.keyCode === 9) { // if Tab key was pressed
console.log('tab pressed');
$('body').addClass('keyfocus');
}
};
$(document).on('mousedown', function(e) {
if (e.button == 0) {
console.log('mouse clicked');
$('body').removeClass('keyfocus');
}
});
body{
font-family: sans-serif;
background: #fff;
margin: 20px;
}
a {
margin: 20px;
}
a:focus,
a:active {
outline: none;
}
.keyfocus a:focus,
.keyfocus a:active{
outline: 1px solid #f00;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment