refactor(nodewrapper): use offsetWidth
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user