@@ -221,30 +221,38 @@ dragElement.init = function init(options) {
221
221
if ( gd . _dragged ) {
222
222
if ( options . doneFn ) options . doneFn ( ) ;
223
223
} else {
224
- if ( options . clickFn ) options . clickFn ( numClicks , initialEvent ) ;
224
+ // If you're in a shadow DOM the target here gets pushed
225
+ // up to the container in the main DOM. (why only here? IDK)
226
+ // Don't make an event at all, just an object that looks like one,
227
+ // since the shadow DOM puts restrictions on what can go in the event,
228
+ // but copy as much as possible since it will be passed on to
229
+ // plotly_click handlers
230
+ var clickEvent ;
231
+ if ( initialEvent . target === initialTarget ) {
232
+ clickEvent = initialEvent ;
233
+ } else {
234
+ clickEvent = {
235
+ target : initialTarget ,
236
+ srcElement : initialTarget ,
237
+ toElement : initialTarget
238
+ } ;
239
+ Object . keys ( initialEvent )
240
+ . concat ( Object . keys ( initialEvent . __proto__ ) )
241
+ . forEach ( k => {
242
+ var v = initialEvent [ k ] ;
243
+ if ( ! clickEvent [ k ] && ( typeof v !== 'function' ) ) {
244
+ clickEvent [ k ] = v ;
245
+ }
246
+ } ) ;
247
+ }
248
+ if ( options . clickFn ) options . clickFn ( numClicks , clickEvent ) ;
225
249
226
250
// If we haven't dragged, this should be a click. But because of the
227
251
// coverSlip changing the element, the natural system might not generate one,
228
252
// so we need to make our own. But right clicks don't normally generate
229
253
// click events, only contextmenu events, which happen on mousedown.
230
254
if ( ! rightClick ) {
231
- var e2 ;
232
-
233
- try {
234
- e2 = new MouseEvent ( 'click' , e ) ;
235
- } catch ( err ) {
236
- var offset = pointerOffset ( e ) ;
237
- e2 = document . createEvent ( 'MouseEvents' ) ;
238
- e2 . initMouseEvent ( 'click' ,
239
- e . bubbles , e . cancelable ,
240
- e . view , e . detail ,
241
- e . screenX , e . screenY ,
242
- offset [ 0 ] , offset [ 1 ] ,
243
- e . ctrlKey , e . altKey , e . shiftKey , e . metaKey ,
244
- e . button , e . relatedTarget ) ;
245
- }
246
-
247
- initialTarget . dispatchEvent ( e2 ) ;
255
+ initialTarget . dispatchEvent ( new MouseEvent ( 'click' , e ) ) ;
248
256
}
249
257
}
250
258
0 commit comments