Skip to content

Instantly share code, notes, and snippets.

@vinzdef
Created September 17, 2020 14:51
Show Gist options
  • Save vinzdef/43c8a0ea6b7aa88124179103859a5746 to your computer and use it in GitHub Desktop.
Save vinzdef/43c8a0ea6b7aa88124179103859a5746 to your computer and use it in GitHub Desktop.
Removes outlines when using a mouse
import {on, off} from '@okiba/dom'
const outlineClass = 'is-outline-hidden'
function disableOutline() {
on(window, 'keydown', enableOutline)
off(window, 'mousemove', disableOutline)
document.body.classList.add(outlineClass)
}
function enableOutline({keyCode}) {
if (keyCode !== 9) return
off(window, 'keydown', enableOutline)
on(window, 'mousemove', disableOutline)
document.body.classList.remove(outlineClass)
}
export default function smartOutline() {
on(window, 'mousemove', disableOutline)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment