refactor(nodewrapper): use offsetWidth

This commit is contained in:
moklick
2019-08-19 16:22:06 +02:00
parent 311a18b769
commit 25991c80a9
7 changed files with 35 additions and 35 deletions
+3 -3
View File
@@ -1,18 +1,18 @@
import { useState, useEffect } from 'react';
const isInput = target => ['INPUT', 'SELECT', 'TEXTAREA'].includes(target.nodeName);
import { isInputNode } from '../utils';
export default function useKeyPress(targetKey) {
const [keyPressed, setKeyPressed] = useState(false);
function downHandler({ key, target }) {
if (key === targetKey && !isInput(target)) {
if (key === targetKey && !isInputNode(target)) {
setKeyPressed(true);
}
}
const upHandler = ({ key, target }) => {
if (key === targetKey && !isInput(target)) {
if (key === targetKey && !isInputNode(target)) {
setKeyPressed(false);
}
};