Skip to content

Commit 7a7fc14

Browse files
authored
fix: Clicking a folder in file explorer panel sometimes fails to open or close it (#1099)
Fixes #1085 - isDragging was always set to true on itemMouseMove which prevented onSelect from firing on even the slightest of mouse movements while clicking - Set isDragging to true only if the mouse moves at least 5 viewport units in the X or Y direction between the mouseDown and mouseUp events (attempted to get this value as close as possible to when the UI changes to indicate dragging)
1 parent e4cb461 commit 7a7fc14

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

packages/components/src/ItemList.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ContextActionUtils } from './context-actions';
1414
import './ItemList.scss';
1515

1616
const log = Log.module('ItemList');
17+
const MIN_DRAG_DELTA = 5;
1718

1819
export 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

Comments
 (0)