How to clear search input when a user clicks outside of search result element

I want to clear search input and close the search result element like the attached image when user clicks outside of the search element.

Here is what I have tried

  • make on-blur workflow to search input element. The problem with this method is if user clicks one of the elements within search result, page navigation I expected does not work as on-blur workflow completes.
  • I can’t make on blur workflow to the whole search element so that it can detect only clicks outside of the search element.

So I am stuck… could anyone help?

Hello, you can use the On blur event. To prevent the clicking into results from also erasing the value, you can use the mousedown event on the results to set up the stop propagation. I have my own custom component on the marketplace for this, and in the documentation, I exactly describe this. Have a look in the See demo, on the bottom of the page/end of the video:

https://marketplace.weweb.io/libraries/df32b91d-b9da-42b3-9e59-47f78fbc2579/

hey I was actually watching your video just now and found the solution right there :grinning:

I was not sure of what the stop propagation event is. I wish there are more documents for it.

Anyway I was able to fix it.Thanks for help always!

1 Like

@Jay12 here you can learn about event propagation Bubbling and capturing