From 1d9f7ab75dbfa9f6c8c60efdecc134387fb6e0ec Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Sun, 24 Apr 2022 23:20:06 -0400 Subject: Fix value picker --- app/src/Keyboard/Keys/Key.js | 6 +++++- app/src/Keyboard/Keys/KeyValue.js | 19 +++++++++++++------ app/src/ValuePicker/index.js | 3 +-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/Keyboard/Keys/Key.js b/app/src/Keyboard/Keys/Key.js index 7b4efcc..7374eab 100644 --- a/app/src/Keyboard/Keys/Key.js +++ b/app/src/Keyboard/Keys/Key.js @@ -119,6 +119,7 @@ export default function Key(props) { setEditing(editing) } function handleSelectBehaviour(event) { + event.stopPropagation() setEditing({ target: event.target, targets: getSearchTargets('behaviour', value), @@ -156,7 +157,10 @@ export default function Key(props) { // @mouseleave="onMouseLeave" > {behaviour ? ( - + {behaviour.code} ) : null} diff --git a/app/src/Keyboard/Keys/KeyValue.js b/app/src/Keyboard/Keys/KeyValue.js index 71f6960..7aea967 100644 --- a/app/src/Keyboard/Keys/KeyValue.js +++ b/app/src/Keyboard/Keys/KeyValue.js @@ -1,3 +1,5 @@ +import { useMemo } from 'react' + import Icon from '../../Common/Icon' import styles from './styles.module.css' @@ -11,16 +13,21 @@ export default function KeyValue(props) { const text = source && {source?.symbol || source?.code} const icon = source?.faIcon && + const handleClick = useMemo(() => function (event) { + event.stopPropagation() + onSelect({ + target: event.target, + codeIndex: index, + code: value, + param + }) + }, [param, value, index, onSelect]) + return ( onSelect({ - target: event.target, - codeIndex: index, - code: value, - param - })} + onClick={handleClick} > {icon || text || } diff --git a/app/src/ValuePicker/index.js b/app/src/ValuePicker/index.js index a98b6a3..d85b5c6 100644 --- a/app/src/ValuePicker/index.js +++ b/app/src/ValuePicker/index.js @@ -31,7 +31,6 @@ function ValuePicker (props) { const [highlighted, setHighlighted] = useState(null) const [showAll, setShowAll] = useState(false) - const results = useMemo(() => { const options = { key: searchKey, limit: 30 } const filtered = fuzzysort.go(query, choices, options) @@ -61,7 +60,7 @@ function ValuePicker (props) { }, [onSelect]) const handleClickOutside = useMemo(() => function(event) { - if (listRef.current?.contains(event.target)) { + if (!listRef.current.contains(event.target)) { onCancel() } }, [listRef, onCancel]) -- cgit v1.2.3