Created
August 9, 2017 23:10
-
-
Save jgierer12/09f74873e7b7507d8c9cf5f42c251de8 to your computer and use it in GitHub Desktop.
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
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