Detect if the user navigate with his keyboard ⌨️ or mouse 🖱️. Then add a matching class to the html element. This allow to remove the blue outline for the mouse users and keeps it at the same time for the keyboard users.
👍 Lite 5kb (2kb Gzipped) ⚡ Fast Native JavaScript 🚫 No Dependencies
Going back and forth between mouse and keyboard navigation
npm i detect-keyboard-user
<script src="https://unpkg.com/detect-keyboard-user"></script>;
const DetectKeyboardUser = require('detect-keyboard-user');
import DetectKeyboardUser from 'detect-keyboard-user';
const myDKU = new DetectKeyboardUser();
Option | Default | Possibilities | Description |
---|---|---|---|
keyboardPriority | true | Boolean (true/false) | By default, should we consider the user is using his keyboard or a pointer (mouse). I suggest you keep it to 'true' to pass the automated accessibility audits. |
Method | Description |
---|---|
myDKU.refresh(); |
You should call this method if you emulate devices with your browser and want to avoid false/positive |
myDKU.destroy(); |
Remove everything 😥 |
The great David Gilbertson and his article on Medium.com | Removing that ugly :focus ring (and keeping it too)
Chrome, Firefox, Safari, Edge, IE 11