Last active
April 3, 2019 12:28
-
-
Save beardcoder/f4557e60b8644ab090d4567feb6b20d4 to your computer and use it in GitHub Desktop.
This helper prevents the focus ring on mouse interaction for bootstap buttons
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
/** | |
* This helper prevents the focus ring on mouse interaction on buttons | |
*/ | |
import forEach from 'lodash-es/forEach'; | |
forEach(...[document.querySelectorAll('.btn')], (element) => { | |
let mouseDown = false; | |
element.addEventListener('mousedown', () => { | |
mouseDown = true; | |
}); | |
element.addEventListener('mouseup', () => { | |
mouseDown = false; | |
}); | |
element.addEventListener('focus', (event) => { | |
if (mouseDown) { | |
event.target.blur(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment