New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useClickOutside
: [bug?] multiple instances of controller
#193
Comments
Hey @pySilver, thanks for opening this issue! I think the behavior you are describing makes sense and is expected. The This applies unless you are explicitly passing a different Or am I misunderstanding what you are describing? |
Hello @marcoroth! Thanks for your reply. Yes, I think I'm observing something else. Let me refer your example. <div id="desktop-view" data-controller="search-form">
<div data-search-form-target="suggestions">search suggestions are shown here when form is active</div>
</div>
...
<div id="mobile-view" data-controller="search-form">
<div data-search-form-target="suggestions">search suggestions are shown here when form is active</div>
</div> // search-form controller
connect() {
useClickOutside(this);
}
clickOutside(event) {
console.log("im triggered", this.element, this.suggestionsTarget);
event.preventDefault();
this._clearSuggestions();
}
_clearSuggestions() {
this.suggestionsTarget.innerHTML = "";
} Now click inside the area of the So it doesn't really look as stimulus-use issue here, but more stimulus itself (?) |
Funny. In fact if I instead use this code: _clearSuggestions() {
this.suggestionsTarget.classList.add("hidden");
} I'm seeing that |
@marcoroth any idea what may cause this or how can I debug the issue? |
@pySilver The only thing that directly comes to mind is that you might be missing a closing You could start by logging and see if One thing that also often helps is to try to re-create this behavior in a minimal setup and see if you can see the same behavior there. Otherwise I don't see anything obvious why it would behave that way. |
Hey @pySilver, I'm just checking in. Did you have any success debugging your issue? |
Hey @marcorot! Unfortunately not. I've had to change the logic a little bit to mitigate the issue. |
useClickOutside
: [bug?] multiple instances of controller
Hi!
I have 2 instances of widget controller called
search-form
. One instance is used for mobile view and the other for larger screens. Both of them are placed in a totally different areas of a page (no parent-child relation). Both of them are implemented as:Im observing the following unexpected behaviour where mobile instance of controller is capturing outside-clicks and triggers
clickOutside
method of all controller instances . I'd expect it will call this method for its own instance, not all of them.Is this a bug or expected behaviour?
The text was updated successfully, but these errors were encountered: