Let's say I open a popup overlay box with a background that can be clicked to close it.
Then in that box I have a text input.
If the user drags their mouse to select all the text from the input and overshots by releasing the mouse over the background, then the click event fires and the whole popup closes.
Of course I could use other events on that background like mousedown
or pointerdown
but it leads to a loophole with all sorts of other issues. For example, if the background uses that then all other elements of the page should use the same type of event in order to make the stopPropagation()
calls work. This creates many problems, such as the fact that a button mousedown/pointerdown will trigger before an input blur
, and so on.
Is there a way to know from the click
event of that background that the mousedown was not initiated on that same element? (meaning it was a drag)
Otherwise, is there another simple way to deal with this issue?
CODE EXAMPLE: https://jsfiddle.net/4aLz1ft7/
EDIT: Of course it should be a reasonably simple solution (or as simple as possible). Adding an event on every input is not realistic because this content could be dynamic, could contain anything else. Ideally the solution would happen with the wrappers themselves (#overlay and #overlay_content).