From f68257d5cc92aa613716b690dd81221966f4e347 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Fri, 19 Apr 2019 09:55:15 -0700 Subject: [PATCH] Simplify focus Target --- js/components/FocusTarget.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/js/components/FocusTarget.tsx b/js/components/FocusTarget.tsx index b3a5deae..ea6b0595 100644 --- a/js/components/FocusTarget.tsx +++ b/js/components/FocusTarget.tsx @@ -28,31 +28,21 @@ function FocusTarget(props: Props) { } }, [windowId, focusedWindowId, setFocus]); - const blurHandler = useCallback(() => { - setFocus(null); - }, [setFocus]); - const ref = useRef(null); useEffect(() => { const { current } = ref; - if (current == null) { + if (current == null || onKeyDown == null) { return; } - const listener = (e: KeyboardEvent) => { - if (windowId === focusedWindowId && onKeyDown != null) { - onKeyDown(e); - } - }; - current.addEventListener("keydown", listener); - return () => current.removeEventListener("keydown", listener); + current.addEventListener("keydown", onKeyDown); + return () => current.removeEventListener("keydown", onKeyDown); }, [onKeyDown, windowId, focusedWindowId]); return (