Skip to content

Instantly share code, notes, and snippets.

@beardcoder
Last active April 3, 2019 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beardcoder/f4557e60b8644ab090d4567feb6b20d4 to your computer and use it in GitHub Desktop.
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 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