-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
add click away on event #5138
Comments
Please use, not delete the issue template in future. You can implement this as an action, please see the API documentation on actions. This will not be implemented as an event modifier for |
Documentation is very vague on this topic, i think this should be easy to implemenet like alpineJS... |
See sveltejs/rfcs#24 |
For Other that might be looking for solution on this U need to use bind this let dropdownEl;
document.addEventListener("click", function (e) {
if (dropdownEl != undefined) {
if (dropdownEl.contains(e.target)) return;
// Don't do anything if this element isn't currently visible.
if (dropdownEl.offsetWidth < 1 && dropdownEl.offsetHeight < 1) return;
dropdown = false;
console.log("dropdown-close");
}
});
on your html Important U Add stopPropagation event modifier on click <button on:click|stopPropagation={toggleDropdown}>
</button
<!-- YOUR DROPDOWN -->
<div bind:this={dropdownEl}>
</div>
`` |
Is there a way you can add this little helper directive on svelte?
on:click|away , i think this is doable... and easy to implement
https://github.com/alpinejs/alpine/blob/master/src/directives/on.js#L7-L26
The text was updated successfully, but these errors were encountered: