From 5625fdfc598b6664e6ebe0a3744f4cc28bd2c897 Mon Sep 17 00:00:00 2001 From: yonadavGit Date: Tue, 18 Jun 2024 15:54:40 +0300 Subject: [PATCH] fix(searchbar): cleaner code, plus avoid setValueInput when vkeyboard not open --- static/js/Autocomplete.jsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/static/js/Autocomplete.jsx b/static/js/Autocomplete.jsx index dc23b2645b..d029830495 100644 --- a/static/js/Autocomplete.jsx +++ b/static/js/Autocomplete.jsx @@ -178,6 +178,12 @@ const SearchInputBox = ({getInputProps, suggestions, highlightedIndex, hideHebre setSearchFocused, searchFocused, submitSearch, redirectToObject}) => { + const getInputValue = () =>{ + return otherDownShiftProps.value || document.getElementsByClassName('keyboardInput')[0].value; + } + const getVirtualKeyboardInputValue = () =>{ + return document.getElementsByClassName('keyboardInput')[0].value; + } useEffect(() => { showVirtualKeyboardIcon(false); // Initially hide the virtual keyboard icon }, []); @@ -191,14 +197,14 @@ const SearchInputBox = ({getInputProps, suggestions, highlightedIndex, hideHebre redirectToObject(highlightedItem); return; } - const inputQuery = otherDownShiftProps.value || document.getElementsByClassName('keyboardInput')[0].value; + const inputQuery = getInputValue(); if (!inputQuery) return; submitSearch(inputQuery); }; const handleSearchButtonClick = (event) => { - const inputQuery = otherDownShiftProps.value || document.getElementsByClassName('keyboardInput')[0].value; + const inputQuery = getInputValue(); if (inputQuery) { submitSearch(inputQuery); } else { @@ -224,14 +230,14 @@ const SearchInputBox = ({getInputProps, suggestions, highlightedIndex, hideHebre const blurSearch = (e) => { onBlur(e); - const oldValue = document.getElementsByClassName('keyboardInput')[0].value; + const oldValue = getVirtualKeyboardInputValue(); const parent = document.getElementById('searchBox'); if (!parent.contains(e.relatedTarget) && !document.getElementById('keyboardInputMaster')) { // debug: comment out the following line: setSearchFocused(false); showVirtualKeyboardIcon(false); } - setInputValue(oldValue) + !document.getElementById('keyboardInputMaster') && setInputValue(oldValue) }; const inputClasses = classNames({