-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
_mouseDown method causing issue with child elements receiving event #2205
Comments
this isn't the right fix. we need to detect that an element (div, span, etc..) has mouse handling and let it handle instead... Not sure how to do that yet... |
@adumesny so it seems gridstack uses |
maybe the child handling the event need to prevent it from propagating up (to the grid item), or marked it was handled so it can skip it there... that list extensible seem like a bandaid and wouldn't work in general (you have span, but no reason the grid itself isn't a span or any dom element. |
@adumesny the problem is that for some reason gridstack gets the |
can you post a reproduceable example please ? can't fix it without one. ideally it would be plain html/js and not use any library I don't want to have to debug... |
@adumesny here is the screenshot that shows that |
I'm adding the event as bubble (not capture, unlike the move) so GS should get the event only if the child didn't consume it , not first crack at it. https://github.com/gridstack/gridstack.js/blob/master/src/dd-draggable.ts#L88 this.dragEl.addEventListener('mousedown', this._mouseDown);
....
protected _mouseDown(e: MouseEvent): boolean {
...
// document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
document.addEventListener('mouseup', this._mouseUp, true);
} so don't think we get that event first... that lib need to consume that event instead. Again I need a reproduceable code showing the issue on our side. |
@adumesny well, I understand your explanation! However, the screenshot above clearly shows the event getting picked up by GS first, and only then by tomselect. I am guessing that b/c the I see a comment by you for the
Perhaps it is time to make the skipMouseDown param extensible? At least it would give me a way to updated it instead of making changes to the core js. |
your callstack doesn't show 'mousedown' handler for that lib at all - I would put a breakpoint there and in GS and see what happens... yes GS does call that lib onBlur() but that doesn't mean it didn't get the mouse down event first and failed to do the right thing. |
of course it shows the mousedown handler! I believe that is the only way for it to be triggered. Since I have tested it thoroughly with all kinds of breakpoints, and deduced that it always goes through GS before it gets to tomselect. If you are not interested in fixing it, at least please make it extensible :) |
we're not on the same page.... where does it show |
@adumesny I think you are missing the point. The issue is that mouse events are processed by the event loop in a specific order. In this particular case you are capturing the
..Hope this makes sense... The blur messes up tomselect into thinking the user changed his mind and closes prematurely. |
@artknight you origonally said (and I quote) so based on that all I can say is that span mouseDown handler should be called before GS gets to see down event (which you failed to show above) and should say it was handled insead of pasisng to GS. But now you say they only do click event, which is a very different thing... @Gezdy ^^^ do you have suggestion since you're the one who added the blur() in Gezdy@5014538 for #2063 that lib cares about click event (down+up), and GS handles the down but messses it up. |
Hello,I will try to check it asap, hope tomorrow.
|
Hi @adumesny, I did the previous correction as a developer and not as an architect, I kept the architecture. The problem mentioned by @artknight is broader. The need is to not call "e.preventDefault()" in certain circumstances. To resolve this, there are 2 different approaches:
I think the best approach is to add a new option as said by @artknight and as we see in comments in your code if we declare a new option:
Then we can skip elements in _mouseDown (dd-draggable.ts) method like this:
This will resolve the @artknight problem. |
I would like the fix it the right way - may need to see what jquery-ui did and it if solved that problem instead of adding a workaround users will have to figure out. Yes, I added that comment about making the fixed list possibly expandable, but not sure that's the best approach... |
I second @Gezdy's point, ...I actually really do like the idea of exposing the |
I think there is a misunderstood. You keep the following part:
You only change this part:
In that way, you let to users the possibility to skip elements without changing the core behaviour. Hope this will help you in your analysis. PS: I understand very well when you say "I would like the fix it the right way" |
I don't have a reproduceable case to debug this, and would need to use the old jquery-ui code to see if they have it working there, but looking at their code they appear to have an option as well... https://api.jqueryui.com/draggable/#option-cancel _mouseDown: function( event ) {
...
// event.target.nodeName works around a bug in IE 8 with
// disabled inputs (#7620)
elIsCancel = ( typeof this.options.cancel === "string" && event.target.nodeName ?
$( event.target ).closest( this.options.cancel ).length : false );
if ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) {
return true;
}
..
this.document
.on( "mousemove." + this.widgetName, this._mouseMoveDelegate )
.on( "mouseup." + this.widgetName, this._mouseUpDelegate );
event.preventDefault();
mouseHandled = true;
return true;
} so maybe it's ok to add as well. doesn't look like they are looking for a click() handler on the parent to skip our mousedown which would be the better fix IMO... |
* you can now specify children that will prevent item from being dragged when clicked on. * fix for gridstack#2205 * updated demo to showcase custom non draggable item
fixed in next release. don't forget to donate if you find this lib useful! |
Subject of the issue
An SPAN inside the
.grid-stack-item
element had a mouseDown event attached, however that was intercepted by the_mouseDown
method.Solution
I ended up adding
span
to theskipMouseDown
array.Hope this helps!
The text was updated successfully, but these errors were encountered: