sickdyd/react-search-autocomplete

How to clear the selected value Programmatically ?

Opened this issue ยท 9 comments

How to clear the value of the input box with the help of code ? Isn't there any function exposed ? There is nothing in the docs as well.

+1

Can't set the input value to an empty string via JavaScript, weird ๐Ÿ˜…

+1,

Any news ?

+1
How could we clear the text if the user pressed esc, or clicked a button of reset? I tried the HTML onChange attriubte which doesn't work with this search bar component.

I will really appreciate if there is a workaround or anyone explain how the text input displayed within the search bar is accessed.

i need help, any news?

Solution:
const handleClick = () => {
const divElements = document.querySelectorAll('.clear-icon');
divElements.forEach((divElement) => {
divElement.click();
});
}
Create function for closed de select ๐Ÿ˜„

Solution: const handleClick = () => { const divElements = document.querySelectorAll('.clear-icon'); divElements.forEach((divElement) => { divElement.click(); }); } Create function for closed de select ๐Ÿ˜„

Can you please provide more details on your implementation? I too can choose .clear-icon through querySelector but clicking it inside of handleOnSelect seemingly does nothing. Already wasted 2 hours on this so greatly appreciate your response

@Junder729 what if .clear-icon is disabled ? is other words isn't displayed !

Did you solution work for this case too ?

Good that the mantainers didn't even bother to help :/

Like this:

const [inputSearchString, setInputSearchString] = useState('' as string);
//...
<ReactSearchAutocomplete
          onSelect={() => {
          //...select logic here
          setInputSearchString('')
          }
          onSearch={(str) => {
            setInputSearchString(str);
          }}
          inputSearchString={inputSearchString}/>