@@ -15,6 +15,7 @@ import { useCallSoon } from '../useCallSoon';
15
15
import { useStableHandler } from '../useStableHandler' ;
16
16
import { useGetOriginalItemOrder } from '../useGetOriginalItemOrder' ;
17
17
import { useDraggingPosition } from './useDraggingPosition' ;
18
+ import { isOutsideOfContainer } from '../controlledEnvironment/layoutUtils' ;
18
19
19
20
const DragAndDropContext = React . createContext < DragAndDropContextProps > (
20
21
null as any
@@ -177,6 +178,20 @@ export const DragAndDropProvider: React.FC<React.PropsWithChildren> = ({
177
178
}
178
179
) ;
179
180
181
+ const onDragLeaveContainerHandler = useStableHandler (
182
+ (
183
+ e : DragEvent ,
184
+ containerRef : React . MutableRefObject < HTMLElement | undefined >
185
+ ) => {
186
+ if ( ! containerRef . current ) return ;
187
+ if (
188
+ isOutsideOfContainer ( e , containerRef . current . getBoundingClientRect ( ) )
189
+ ) {
190
+ setDraggingPosition ( undefined ) ;
191
+ }
192
+ }
193
+ ) ;
194
+
180
195
const onDropHandler = useStableHandler ( ( ) => {
181
196
if ( ! draggingItems || ! draggingPosition || ! environment . onDrop ) {
182
197
return ;
@@ -287,6 +302,7 @@ export const DragAndDropProvider: React.FC<React.PropsWithChildren> = ({
287
302
itemHeight : itemHeight . current ,
288
303
isProgrammaticallyDragging,
289
304
onDragOverTreeHandler,
305
+ onDragLeaveContainerHandler,
290
306
viableDragPositions,
291
307
} ) ,
292
308
[
@@ -297,6 +313,7 @@ export const DragAndDropProvider: React.FC<React.PropsWithChildren> = ({
297
313
isProgrammaticallyDragging ,
298
314
itemHeight ,
299
315
onDragOverTreeHandler ,
316
+ onDragLeaveContainerHandler ,
300
317
onStartDraggingItems ,
301
318
programmaticDragDown ,
302
319
programmaticDragUp ,
0 commit comments