Using `return false` and/or `stopPropagation` on click events doesn't play nice with other libraries
See original GitHub issueAny library that binds click events to the document could potentially have functionality broken because jquery-ujs stops event propagation from [data-remote]
clicks.
For example, most tooltip libraries are supposed to hide a shown tooltip when you click anywhere outside of the tooltip target element, but if your click outside happens to be on a link with a data-remote
attribute, that event gets killed and the tooltip doesn’t go away. Obviously this is a minor example, but it should help illustrate the conflict.
Since jquery-ujs is very high-level and abstract, I personally don’t see any compelling reasons (other than perhaps historical) for it to be stopping event propagation.
Admittedly, making this change would likely break functionality on existing sites, so perhaps it could be set with a config option, so projects that rely on this behavior can still have it.
If this is a direction the jquery-ujs project is willing to go, I’d be happy to submit a pull request with the changes.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
I vote +1 for using just
preventDefault
instead ofreturn false
, because now I can’t trigger click handlers on thedocument
.My use case:
I’m opening popup and I want to close it when user clicks on any element outside of this popup.
It works well, except when I click on a link with
[data-remote]
attribute. I think that when a click event bubbles up to thedocument
, it reaches handler for[data-remote]
first, which in turn prevents it from going further into my handler.For now, I use an ugly workaround like this:
I don’t see any reason to include
return false;
instead ofpreventDefault
in similar cases (e.g. css-tricks advises to usepreventDefault
), but I didn’t test it with old and obscure browsers like IE6-7.@JangoSteve What’s the word on this? It’s been 5 months.