MCPcopy Create free account
hub / github.com/adobe/react-spectrum / onDragLeave

Function onDragLeave

packages/react-aria/src/dnd/useDrop.ts:280–314  ·  view source on GitHub ↗
(e: DragEvent)

Source from the content-addressed store, hash-verified

278 };
279
280 let onDragLeave = (e: DragEvent) => {
281 e.preventDefault();
282 e.stopPropagation();
283
284 // We would use e.relatedTarget to detect if the drag is still inside the drop target,
285 // but it is always null in WebKit. https://bugs.webkit.org/show_bug.cgi?id=66547
286 // Instead, we track all of the targets of dragenter events in a set, and remove them
287 // in dragleave. When the set becomes empty, we've left the drop target completely.
288 // We must also remove any elements that are no longer in the DOM, because dragleave
289 // events will never be fired for these. This can happen, for example, with drop
290 // indicators between items, which disappear when the drop target changes.
291
292 let target = getEventTarget(e);
293 state.dragOverElements.delete(target);
294
295 // Only remove stale elements when leaving the drop target itself.
296 // Avoids issues with portal children bubbling dragleave events through the React tree.
297 if (target === e.currentTarget) {
298 for (let element of state.dragOverElements) {
299 if (!nodeContains(e.currentTarget, element)) {
300 state.dragOverElements.delete(element);
301 }
302 }
303 }
304
305 if (state.dragOverElements.size > 0) {
306 return;
307 }
308
309 if (state.dropEffect !== 'none') {
310 fireDropExit(e);
311 }
312
313 clearTimeout(state.dropActivateTimer);
314 };
315
316 let onDrop = (e: DragEvent) => {
317 e.preventDefault();

Callers

nothing calls this directly

Calls 4

getEventTargetFunction · 0.90
nodeContainsFunction · 0.90
fireDropExitFunction · 0.85
deleteMethod · 0.80

Tested by

no test coverage detected