Improving Search Functionalities
Our search bar works, but we can still improve it a bit. It would be nice if the modal was reset when we delete all the characters in the search bar, as well as when we click outside the window. However, the latter might be tricky. To get the “outside the window” part to work, by definition, we need to capture click events outside the scope of our Stimulus controller. Luckily, Stimulus has a way to do that.
First, we need to add an action to our search results object: