@@ -14,7 +14,7 @@ import {announce} from '@react-aria/live-announcer';
1414import { ariaHideOutside } from '@react-aria/overlays' ;
1515import { DragEndEvent , DragItem , DropActivateEvent , DropEnterEvent , DropEvent , DropExitEvent , DropItem , DropOperation , DropTarget as DroppableCollectionTarget , FocusableElement } from '@react-types/shared' ;
1616import { getDragModality , getTypes } from './utils' ;
17- import { isVirtualClick , isVirtualPointerEvent , nodeContains } from '@react-aria/utils' ;
17+ import { getEventTarget , isVirtualClick , isVirtualPointerEvent , nodeContains } from '@react-aria/utils' ;
1818import type { LocalizedStringFormatter } from '@internationalized/string' ;
1919import { RefObject , useEffect , useState } from 'react' ;
2020
@@ -243,7 +243,7 @@ class DragSession {
243243 this . cancelEvent ( e ) ;
244244
245245 if ( e . key === 'Enter' ) {
246- if ( e . altKey || nodeContains ( this . getCurrentActivateButton ( ) , e . target as Node ) ) {
246+ if ( e . altKey || nodeContains ( this . getCurrentActivateButton ( ) , getEventTarget ( e ) as Node ) ) {
247247 this . activate ( this . currentDropTarget , this . currentDropItem ) ;
248248 } else {
249249 this . drop ( ) ;
@@ -257,25 +257,25 @@ class DragSession {
257257
258258 onFocus ( e : FocusEvent ) : void {
259259 let activateButton = this . getCurrentActivateButton ( ) ;
260- if ( e . target === activateButton ) {
260+ if ( getEventTarget ( e ) === activateButton ) {
261261 // TODO: canceling this breaks the focus ring. Revisit when we support tabbing.
262262 this . cancelEvent ( e ) ;
263263 return ;
264264 }
265265
266266 // Prevent focus events, except to the original drag target.
267- if ( e . target !== this . dragTarget . element ) {
267+ if ( getEventTarget ( e ) !== this . dragTarget . element ) {
268268 this . cancelEvent ( e ) ;
269269 }
270270
271271 // Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.
272- if ( ! ( e . target instanceof HTMLElement ) || e . target === this . dragTarget . element ) {
272+ if ( ! ( getEventTarget ( e ) instanceof HTMLElement ) || getEventTarget ( e ) === this . dragTarget . element ) {
273273 return ;
274274 }
275275
276276 let dropTarget =
277- this . validDropTargets . find ( target => target . element === e . target as HTMLElement ) ||
278- this . validDropTargets . find ( target => nodeContains ( target . element , e . target as HTMLElement ) ) ;
277+ this . validDropTargets . find ( target => target . element === getEventTarget ( e ) as HTMLElement ) ||
278+ this . validDropTargets . find ( target => nodeContains ( target . element , getEventTarget ( e ) as HTMLElement ) ) ;
279279
280280 if ( ! dropTarget ) {
281281 // if (e.target === activateButton) {
@@ -289,7 +289,7 @@ class DragSession {
289289 return ;
290290 }
291291
292- let item = dropItems . get ( e . target as HTMLElement ) ;
292+ let item = dropItems . get ( getEventTarget ( e ) as HTMLElement ) ;
293293 if ( dropTarget ) {
294294 this . setCurrentDropTarget ( dropTarget , item ) ;
295295 }
@@ -302,7 +302,7 @@ class DragSession {
302302 return ;
303303 }
304304
305- if ( e . target !== this . dragTarget . element ) {
305+ if ( getEventTarget ( e ) !== this . dragTarget . element ) {
306306 this . cancelEvent ( e ) ;
307307 }
308308
@@ -321,15 +321,15 @@ class DragSession {
321321 this . cancelEvent ( e ) ;
322322 if ( isVirtualClick ( e ) || this . isVirtualClick ) {
323323 let dropElements = dropItems . values ( ) ;
324- let item = [ ...dropElements ] . find ( item => item . element === e . target as HTMLElement || nodeContains ( item . activateButtonRef ?. current , e . target as HTMLElement ) ) ;
325- let dropTarget = this . validDropTargets . find ( target => nodeContains ( target . element , e . target as HTMLElement ) ) ;
324+ let item = [ ...dropElements ] . find ( item => item . element === getEventTarget ( e ) as HTMLElement || nodeContains ( item . activateButtonRef ?. current , getEventTarget ( e ) as HTMLElement ) ) ;
325+ let dropTarget = this . validDropTargets . find ( target => nodeContains ( target . element , getEventTarget ( e ) as HTMLElement ) ) ;
326326 let activateButton = item ?. activateButtonRef ?. current ?? dropTarget ?. activateButtonRef ?. current ;
327- if ( nodeContains ( activateButton , e . target as HTMLElement ) && dropTarget ) {
327+ if ( nodeContains ( activateButton , getEventTarget ( e ) as HTMLElement ) && dropTarget ) {
328328 this . activate ( dropTarget , item ) ;
329329 return ;
330330 }
331331
332- if ( e . target === this . dragTarget . element ) {
332+ if ( getEventTarget ( e ) === this . dragTarget . element ) {
333333 this . cancel ( ) ;
334334 return ;
335335 }
@@ -350,7 +350,7 @@ class DragSession {
350350
351351 cancelEvent ( e : Event ) : void {
352352 // Allow focusin and focusout on the drag target so focus ring works properly.
353- if ( ( e . type === 'focusin' || e . type === 'focusout' ) && ( e . target === this . dragTarget ?. element || e . target === this . getCurrentActivateButton ( ) ) ) {
353+ if ( ( e . type === 'focusin' || e . type === 'focusout' ) && ( getEventTarget ( e ) === this . dragTarget ?. element || getEventTarget ( e ) === this . getCurrentActivateButton ( ) ) ) {
354354 return ;
355355 }
356356
0 commit comments