Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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