Skip to content

Commit a249854

Browse files
authored
Merge pull request #228 from PabloDiablo/master
Fixes #227 issue where onDragStop is fired on mouse move over pane
2 parents 0bfd3a8 + 88134a2 commit a249854

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default class SimpleControlledFullExample extends React.Component<{}, Sta
152152
| `onResize` | |<code>(e: MouseEvent &#124; TouchEvent, key: string, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void</code>| `undefined` | It is called when `Pane` component resize. |
153153
| `onResizeStop` | |<code>(e: MouseEvent &#124; TouchEvent, key: string, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void</code>| `undefined` | It is called when `Pane` component resize stop. |
154154
| `onDragStart` | |<code>(e: React.MouseEvent<HTMLElement> &#124; React.TouchEvent<HTMLElement>, key: string, elementRef: HTMLElement) => void</code> | `undefined` | It is called when `Pane` component dragging starts. |
155-
| `onDragStop` | |<code>(e: MouseEvent &#124; TouchEvent, key: PaneKey, elementRef: HTMLElement) => void</code> | `undefined` | It is called when `Pane` component dragging stop. |
155+
| `onDragStop` | |<code>(e: MouseEvent &#124; TouchEvent, key: PaneKey, elementRef: HTMLElement, order: string[]) => void</code> | `undefined` | It is called when `Pane` component dragging stop. |
156156
157157
## PaneComponent
158158

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)