Skip to content

Instantly share code, notes, and snippets.

@jgierer12
Created August 9, 2017 23:10
Show Gist options
  • Save jgierer12/09f74873e7b7507d8c9cf5f42c251de8 to your computer and use it in GitHub Desktop.
Save jgierer12/09f74873e7b7507d8c9cf5f42c251de8 to your computer and use it in GitHub Desktop.
let clicked = false;
// `mousedown` always seems to fire before `focusin`.
// (But within the same millisecond).
document.addEventListener('mousedown', () => {
clicked = true;
setTimeout(() => clicked = false, 1);
});
// `focusin` is the bubbling version of `focus`.
document.addEventListener('focusin', () => {
// Remove `focus-ring` class from body if user clicked or tapped.
// Otherwise, add it.
document.body.classList[clicked ? 'remove' : 'add']('focus-ring');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment