@@ -14,6 +14,7 @@ import { ContextActionUtils } from './context-actions';
1414import './ItemList.scss' ;
1515
1616const log = Log . module ( 'ItemList' ) ;
17+ const MIN_DRAG_DELTA = 5 ;
1718
1819export interface DefaultListItem {
1920 value ?: string ;
@@ -80,6 +81,8 @@ type ItemListState = {
8081 isDragging : boolean ;
8182 isStuckToBottom : boolean ;
8283 scrollOffset : number | null ;
84+ mouseX : number | null ;
85+ mouseY : number | null ;
8386} ;
8487
8588/**
@@ -179,6 +182,8 @@ export class ItemList<T> extends PureComponent<
179182 isDragging : false ,
180183 isStuckToBottom : isStickyBottom ,
181184 scrollOffset : null ,
185+ mouseX : null ,
186+ mouseY : null ,
182187 } ;
183188 }
184189
@@ -418,7 +423,11 @@ export class ItemList<T> extends PureComponent<
418423 return ;
419424 }
420425
421- this . setState ( { mouseDownIndex : index } ) ;
426+ this . setState ( {
427+ mouseDownIndex : index ,
428+ mouseX : e . clientX ,
429+ mouseY : e . clientY ,
430+ } ) ;
422431
423432 window . addEventListener ( 'mouseup' , this . handleWindowMouseUp ) ;
424433
@@ -451,12 +460,15 @@ export class ItemList<T> extends PureComponent<
451460
452461 handleItemMouseMove ( itemIndex : number , e : React . MouseEvent ) : void {
453462 const { isDragSelect, isMultiSelect, disableSelect } = this . props ;
454- const { mouseDownIndex, selectedRanges } = this . state ;
463+ const { mouseDownIndex, selectedRanges, mouseX , mouseY } = this . state ;
455464
456465 if ( mouseDownIndex == null || disableSelect ) return ;
457466
458- this . setState ( { isDragging : true } ) ;
459-
467+ const mouseMoveX = Math . abs ( e . clientX - ( mouseX ?? 0 ) ) ;
468+ const mouseMoveY = Math . abs ( e . clientY - ( mouseY ?? 0 ) ) ;
469+ if ( mouseMoveX > MIN_DRAG_DELTA && mouseMoveY > MIN_DRAG_DELTA ) {
470+ this . setState ( { isDragging : true } ) ;
471+ }
460472 if ( isDragSelect || mouseDownIndex === itemIndex ) {
461473 this . focusItem ( itemIndex ) ;
462474
0 commit comments