Skip to content

Commit

Permalink
Update cancel check to be shadowRoot compatible
Browse files Browse the repository at this point in the history
This proposal is made to correctly check if the event should be canceled if the first element in the composedPath (or the event.target) matches with the options.cancel selector
  • Loading branch information
malarahfelipe committed Jun 10, 2022
1 parent e21a254 commit 3a1b590
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ui/widgets/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ return $.widget( "ui.mouse", {
}
},

/**
*
* @param {MouseEvent & { originalEvent: MouseEvent }} event
* @returns {boolean}
*/
_mouseDown: function( event ) {

// don't let more than one widget handle mouseStart
Expand All @@ -89,13 +94,15 @@ return $.widget( "ui.mouse", {

this._mouseDownEvent = event;

let [ first = event.target ] = 'composedPath' in event.originalEvent && event.originalEvent.composedPath() || []

var that = this,
btnIsLeft = ( event.which === 1 ),

// 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 );
elIsCancel = ( typeof this.options.cancel === "string" && first.nodeName ?
$( first ).closest( this.options.cancel ).length : false );
if ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) {
return true;
}
Expand Down

0 comments on commit 3a1b590

Please sign in to comment.