Skip to content

Commit a919cfd

Browse files
author
Paul Crane
committed
Fixed onDragStop to only fire on drop. Added order as fourth param to onDragStop.
1 parent 1452640 commit a919cfd

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ build/
55
src/*.js
66
.rpt2_cache
77
*.d.ts
8-
cypress/videos
8+
cypress/videos
9+
.idea
10+
.vscode

src/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export type SortablePaneProps = {
8585
key: PaneKey,
8686
elementRef: HTMLElement,
8787
) => void;
88-
onDragStop?: (e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement) => void;
88+
onDragStop?: (e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement, order: string[]) => void;
8989
onOrderChange?: (order: string[]) => void;
9090
className?: string;
9191
disableEffect?: boolean;
@@ -500,14 +500,16 @@ class SortablePane extends React.Component<SortablePaneProps, State> {
500500
handleMouseUp(e: MouseEvent | TouchEvent) {
501501
const children = this.props.children || [];
502502
if (children.length === 0) return;
503+
const wasPressed = this.state.isPressed;
503504
this.setState({ isPressed: false, delta: 0 });
504505
const child = children[this.state.lastPressed];
505506
const lastPressedId = child.key;
506507
if (!this.props.isSortable) return;
507-
if (this.props.onDragStop) {
508+
const panes = this.state.panes;
509+
if (this.props.onDragStop && wasPressed) {
508510
const c = this.panes.find(p => p.key === child.key);
509511
if (c && c.ref) {
510-
this.props.onDragStop(e, child.key, c.ref as HTMLElement);
512+
this.props.onDragStop(e, child.key, c.ref as HTMLElement, panes.map(p => String(p.key)));
511513
}
512514
}
513515
}

src/react-sortable-pane.es5.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type SortablePaneProps = {
1717
onResizeStop?: (e: MouseEvent | TouchEvent, key: PaneKey, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void,
1818
onResizeStart?: (e: SyntheticMouseEvent<HTMLElement> | SyntheticTouchEvent<HTMLElement>, key: PaneKey, dir: PaneResizeDirection) => void,
1919
onDragStart?: (e: SyntheticMouseEvent<HTMLElement> | SyntheticTouchEvent<HTMLElement>, key: PaneKey, elementRef: HTMLElement) => void,
20-
onDragStop?: (e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement) => void,
20+
onDragStop?: (e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement, order: string[]) => void,
2121
onOrderChange?: (order: string[]) => void,
2222
className?: string,
2323
disableEffect?: boolean,

0 commit comments

Comments
 (0)