From a79a987f5e98bcc04a30ea707b0bea6d50e6b5bc Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Sat, 2 Apr 2022 09:34:28 +0200 Subject: [PATCH] Fix for onenter with selection --- src/panelWebView/components/TagPicker.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/panelWebView/components/TagPicker.tsx b/src/panelWebView/components/TagPicker.tsx index ba621769..1cd10961 100644 --- a/src/panelWebView/components/TagPicker.tsx +++ b/src/panelWebView/components/TagPicker.tsx @@ -153,8 +153,8 @@ const TagPicker: React.FunctionComponent = (props: React.PropsW * Add the new item to the data * @param e */ - const onEnterData = useCallback((e: React.KeyboardEvent, closeMenu: Function) => { - if (e.key === "Enter" && e.type === "keydown") { + const onEnterData = useCallback((e: React.KeyboardEvent, closeMenu: Function, highlightedIndex: any) => { + if (e.key === "Enter" && e.type === "keydown" && (highlightedIndex === null || highlightedIndex === undefined)) { const value = inputRef.current?.value.trim(); if (!value) { return; @@ -228,7 +228,7 @@ const TagPicker: React.FunctionComponent = (props: React.PropsW inputValue={inputValue} onInputValueChange={(value) => setInputValue(value)}> { - ({ getInputProps, getItemProps, getMenuProps, isOpen, inputValue, getRootProps, openMenu, closeMenu, clearSelection }) => ( + ({ getInputProps, getItemProps, getMenuProps, isOpen, inputValue, getRootProps, openMenu, closeMenu, clearSelection, highlightedIndex }) => ( <>
= (props: React.PropsW ref: inputRef, onFocus: openMenu as any, onClick: openMenu as any, - onKeyDown: (e) => onEnterData(e, closeMenu), + onKeyDown: (e) => onEnterData(e, closeMenu, highlightedIndex), onBlur: () => { closeMenu(); unsetFocus();