react-focus-onkeydown
Advanced tools
+24
| import { useEffect } from 'react'; | ||
| export default (ref, active = true) => { | ||
| const windowKeyDown = (e) => { | ||
| // Auto-focus the current input when a key is typed | ||
| if (!(e.ctrlKey || e.metaKey || e.altKey)) { | ||
| ref.current.focus(); | ||
| } | ||
| }; | ||
| useEffect(() => { | ||
| if (active) { | ||
| window.addEventListener('keydown', windowKeyDown); | ||
| } else { | ||
| window.removeEventListener('keydown', windowKeyDown); | ||
| } | ||
| return () => { | ||
| if (active) { | ||
| window.removeEventListener('keydown', windowKeyDown); | ||
| } | ||
| }; | ||
| }, [active]); | ||
| }; |
+2
-2
| { | ||
| "name": "react-focus-onkeydown", | ||
| "version": "5.0.0", | ||
| "version": "5.0.1", | ||
| "description": "React hook for getting focus of a component when a key is pressed anywhere in the page", | ||
@@ -23,3 +23,3 @@ "type": "module", | ||
| "files": [ | ||
| "dist" | ||
| "index.js" | ||
| ], | ||
@@ -26,0 +26,0 @@ "keywords": [ |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
5322
11.95%4
33.33%21
Infinity%0
-100%