Skip to content

Commit

Permalink
fix(searchbar): cleaner code, plus avoid setValueInput when vkeyboard…
Browse files Browse the repository at this point in the history
… not open
  • Loading branch information
yonadavGit committed Jun 18, 2024
1 parent d6bfddb commit 5625fdf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions static/js/Autocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, []);
Expand All @@ -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 {
Expand All @@ -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({
Expand Down

0 comments on commit 5625fdf

Please sign in to comment.