Skip to content

Feat/add onDragStart prop #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ __[Demo](http://jakesidsmith.github.io/react-reorder/)__
selected={this.state.selected}
// The key to compare from the selected item object with each item object
selectedKey='uuid'
// Function that is called on when draging starts (after holding time)
onStartDrag={this.dragStart}
// Allows reordering to be disabled
disableReorder={false}/>
```
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
},
startDrag: function (dragOffset, draggedStyle) {
if (!this.props.disableReorder) {
if (typeof this.props.onStartDrag === 'function') {
this.props.onStartDrag(dragOffset);
}
this.setState({
dragOffset: dragOffset,
draggedStyle: draggedStyle,
Expand Down Expand Up @@ -114,9 +117,10 @@
window.addEventListener('mousemove', this.onMouseMove); // Mouse move

// Touch events
window.addEventListener('touchend', this.onMouseUp); // Touch up
window.addEventListener('touchmove', this.onMouseMove); // Touch move
window.addEventListener('touchend', this.onMouseUp, { passive: false }); // Touch up
window.addEventListener('touchmove', this.onMouseMove, { passive: false }); // Touch move

// Prevent context menu
window.addEventListener('contextmenu', this.preventDefault);
},
onMouseUp: function (event) {
Expand Down