MCPcopy Index your code
hub / github.com/adobe/react-spectrum / onDrop

Function onDrop

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

Source from the content-addressed store, hash-verified

314 };
315
316 let onDrop = (e: DragEvent) => {
317 e.preventDefault();
318 e.stopPropagation();
319 // Track drop effect in global state for Chrome Android. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951
320 // Android onDragEnd always returns "none" as its drop effect.
321 setGlobalDropEffect(state.dropEffect);
322
323 if (typeof options.onDrop === 'function') {
324 let dropOperation = DROP_EFFECT_TO_DROP_OPERATION[state.dropEffect];
325 let items = readFromDataTransfer(e.dataTransfer);
326
327 let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
328 let event: DropEvent = {
329 type: 'drop',
330 x: e.clientX - rect.x,
331 y: e.clientY - rect.y,
332 items,
333 dropOperation
334 };
335
336 options.onDrop(event);
337 }
338
339 let dndStateSnapshot = {...globalDndState};
340 state.dragOverElements.clear();
341 fireDropExit(e);
342 clearTimeout(state.dropActivateTimer);
343 // If there wasn't a collection being tracked as a dragged collection, then we are in a case where a non RSP drag is dropped on a
344 // RSP collection and thus we don't need to preserve the global drop effect
345 if (dndStateSnapshot.draggingCollectionRef == null) {
346 setGlobalDropEffect(undefined);
347 } else {
348 // Otherwise we need to preserve the global dnd state for onDragEnd's isInternal check.
349 // At the moment fireDropExit may clear dropCollectionRef (i.e. useDroppableCollection's provided onDropExit, required to clear dropCollectionRef when exiting a valid drop target)
350 setGlobalDnDState(dndStateSnapshot);
351 }
352 };
353
354 let onDropEnter = useEffectEvent((e: DropEnterEvent) => {
355 if (typeof options.onDropEnter === 'function') {

Callers

nothing calls this directly

Calls 5

setGlobalDropEffectFunction · 0.90
readFromDataTransferFunction · 0.90
setGlobalDnDStateFunction · 0.90
fireDropExitFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected