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
: Documentation Maybe Unclear?
#95
Comments
OK, in playing with it a bit more after writing out my issue, I tried moving the
Where when the I guess the intended idea is that each element would have it's own controller and therefore would have it's own |
Yes the documentation could probably be improved. with regards to your example <div data-controller='header-menu'>
<span data-action="header-menu:click:outside->header-menu#close" />
<span data-action="header-menu:click:outside->header-menu#close" />
</div> it doesn't work because the event bubbles up from the root element. So you inner divs cannot directly listen to this event. On solution would be to listen at the document level if you are sure to have only one of those events on this page <div data-controller='header-menu'>
<span data-action="header-menu:click:outside@document->header-menu#close" />
<span data-action="header-menu:click:outside@document->header-menu#close" />
</div> The primary intent of the events was more to communicate with other controllers. At least this is how I use them.... in your case you might want to have something like this also clickOutside(event) {
this.close()
} |
useClickOutside
: Documentation Maybe Unclear?
Hi there, maybe I'm doing something wrong but when I try to use the event example in the docs here, I can't seem to get it to work. I've changed
modal
to the name of my controller and tried giving it a custom prefix. Below is my implementation in my ERB template:And my controller:
Currently only the
clickOutside
event gets called. When I remove it nothing happens. Other aspects of the controller using default Stimulus work fine, it just seems to be this event based useClickOutside that isn't so far.Am I just missing something, or is something broken?
EDIT:
I am using the navbar example as my base code to test out Stimulus as seen here: https://tailwindui.com/components/application-ui/navigation/navbars#component-70a9bdf83ef2c8568c5cddf6c39c2331.
The text was updated successfully, but these errors were encountered: