fix(nodes): no remove when in input

This commit is contained in:
moklick
2019-08-05 17:12:09 +02:00
parent f90f3c26cd
commit 1d81205d4f
6 changed files with 131 additions and 33 deletions
+6 -4
View File
@@ -1,16 +1,18 @@
import { useState, useEffect } from 'react';
const isInput = target => ['INPUT', 'SELECT', 'TEXTAREA'].includes(target.nodeName);
export function useKeyPress(targetKey) {
const [keyPressed, setKeyPressed] = useState(false);
function downHandler({ key }) {
if (key === targetKey) {
function downHandler({ key, target }) {
if (key === targetKey && !isInput(target)) {
setKeyPressed(true);
}
}
const upHandler = ({ key }) => {
if (key === targetKey) {
const upHandler = ({ key, target }) => {
if (key === targetKey && !isInput(target)) {
setKeyPressed(false);
}
};